AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Advanced ShowMOTDPanel (https://forums.alliedmods.net/showthread.php?t=232476)

Dr. McKay 12-31-2013 02:28

Advanced ShowMOTDPanel
 
2 Attachment(s)
I haven't actually tested this in-game, but it should work fine.

This is an enhanced version of ShowMOTDPanel that allows for:
  • Hidden MOTD panels
  • Big MOTD panel (in TF2)
  • Verification that the client can actually receive MOTD panels before sending it

PHP Code:

/**
 * Displays an MOTD panel to a client with advanced options
 * 
 * @param client        Client index the panel should be shown to
 * @param title            Title of the MOTD panel (not displayed on all games)
 * @param msg            Content of the MOTD panel; could be a URL, plain text, or a stringtable index
 * @param type            Type of MOTD this is, one of MOTDPANEL_TYPE_TEXT, MOTDPANEL_TYPE_INDEX, MOTDPANEL_TYPE_URL, MOTDPANEL_TYPE_FILE
 * @param visible        Whether the panel should be shown to the client
 * @param big            true if this should be a big MOTD panel (TF2 only)
 * @param verify        true if we should check if the client can actually receive HTML MOTDs before sending it, false otherwise
 * @param callback        A callback to be called if we determine that the client can't receive HTML MOTDs
 * @noreturn
 */
stock void AdvMOTD_ShowMOTDPanel(int client, const char[] title, const char[] msgint type=MOTDPANEL_TYPE_INDEXbool visible=truebool big=falsebool verify=falseMOTDFailure callback=INVALID_FUNCTION)

typedef MOTDFailure = function void (int clientMOTDFailureReason reason);

enum MOTDFailureReason {
    
MOTDFailure_Unknown// Failure reason unknown
    
MOTDFailure_Disabled// Client has explicitly disabled HTML MOTDs
    
MOTDFailure_Matchmaking// HTML MOTD is disabled by Quickplay/matchmaking (TF2 only)
    
MOTDFailure_QueryFailed // cl_disablehtmlmotd convar query failed
}; 

Example:

PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <advanced_motd>

public void OnPluginStart() {
    
RegConsoleCmd("sm_google"Command_Google"Opens Google in a large MOTD window");
}

public 
Action Command_Google(int clientint args) {
    
AdvMOTD_ShowMOTDPanel(client"Google""http://www.google.com"MOTDPANEL_TYPE_URLtruetruetrueOnMOTDFailure);
    return 
Plugin_Handled;
}

public 
void OnMOTDFailure(int clientMOTDFailureReason reason) {
    if(
reason == MOTDFailure_Disabled) {
        
PrintToChat(client"[SM] You have HTML MOTDs disabled.");
    } else if(
reason == MOTDFailure_Matchmaking) {
        
PrintToChat(client"[SM] You cannot view HTML MOTDs because you joined via Quickplay.");
    } else if(
reason == MOTDFailure_QueryFailed) {
        
PrintToChat(client"[SM] Unable to verify that you can view HTML MOTDs.");
    } else {
        
PrintToChat(client"[SM] Unable to verify that you can view HTML MOTDs for an unknown reason.");
    }



404UserNotFound 12-31-2013 04:14

Re: Advanced ShowMOTDPanel
 
I. Freakin'. Love. You.

Alex30555 12-31-2013 05:22

Re: Advanced ShowMOTDPanel
 
Nice :D Thanks.

404UserNotFound 01-01-2014 13:15

Re: Advanced ShowMOTDPanel
 
Thanks to this excellent native, I was able to FINALLY create a working "Big MOTD on connect" plugin. It uses some code from MasteroftheXP's Block MOTD plugin which is why there seems to be an issue where using this causes players to not be able to select a class or a team.

Here's the code

Spoiler

Dr. McKay 01-01-2014 15:45

Re: Advanced ShowMOTDPanel
 
If the HTML MOTD fails, you should send them a regular ShowMOTDPanel text MOTD.

Also, why are you hooking the "Train" message?

404UserNotFound 01-01-2014 15:54

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Dr. McKay (Post 2079596)
If the HTML MOTD fails, you should send them a regular ShowMOTDPanel text MOTD.

Also, why are you hooking the "Train" message?

It's from the Block MOTD plugin from MasteroftheXP. I didn't know what it was, so I just kept it in there.

The HTML MOTD displays properly, but (and this may have been because I unloaded the plugin whilst the MOTD panel was up) it disallowed me from choosing a team or even joining the game.

The only reason I was trying to make a "big MOTD on connect" plugin was for a friend who wanted it for his server.

Dr. McKay 01-01-2014 16:56

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by abrandnewday (Post 2079602)
It's from the Block MOTD plugin from MasteroftheXP. I didn't know what it was, so I just kept it in there.

The HTML MOTD displays properly, but (and this may have been because I unloaded the plugin whilst the MOTD panel was up) it disallowed me from choosing a team or even joining the game.

The only reason I was trying to make a "big MOTD on connect" plugin was for a friend who wanted it for his server.

The big MOTD destroys vgui panels underneath it, including the team selection screen.

psychonic's Dynamic MOTD plugin has an option to use the big MOTD.

404UserNotFound 01-01-2014 17:15

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Dr. McKay (Post 2079636)
The big MOTD destroys vgui panels underneath it, including the team selection screen.

psychonic's Dynamic MOTD plugin has an option to use the big MOTD.

Well wait....if it destroys the team selection screen, why would someone use a big MOTD on connect? No-one would be able to join!

Dr. McKay 01-01-2014 17:20

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by abrandnewday (Post 2079643)
Well wait....if it destroys the team selection screen, why would someone use a big MOTD on connect? No-one would be able to join!

psychonic's plugin accounts for and fixes this.

404UserNotFound 01-01-2014 17:26

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Dr. McKay (Post 2079647)
psychonic's plugin accounts for and fixes this.

Ohhhhhhh. I see now! Thanks for clarifying :D

KissLick 09-18-2014 13:50

Re: Advanced ShowMOTDPanel
 
Ciao,

I use this include, and sometimes my MOTDs only flicks/blinks (just open and immediately close). Does anyone know whats wrong and how to fix it?

My code:
PHP Code:

public Action:Hook_PlayerChatclientargc )
{
    if( !
Client_IsIngameclient ) )
        return 
Plugin_Continue;

    
decl String:sText512 ], String:url128 ];

    
GetCmdArgStringsTextsizeofsText ) );
    
StripQuotessText );
        
    if( 
sText] != '#' && sText] != '!' )
        return 
Plugin_Continue;
    
    if( 
GetTrieStringg_linkssTexturlsizeofurl ) ) )
        
AdvMOTD_ShowMOTDPanelclient"title"urlMOTDPANEL_TYPE_URL );

    return 
Plugin_Continue;



404UserNotFound 10-28-2014 16:53

Re: Advanced ShowMOTDPanel
 
Bit of a warning when compiling a plugin using this in a 1.7 environment:

"Warning 237: coercing functions to and from primitives is unsupported and will be removed in the future"

...wat

Chdata 10-29-2014 07:00

Re: Advanced ShowMOTDPanel
 
wat is a big motd

Powerlord 10-29-2014 10:50

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Chdata (Post 2217288)
wat is a big motd

As far as I recall, it removes the chalkboard that normally surrounds the MOTD.

zeroibis 10-29-2014 14:28

Re: Advanced ShowMOTDPanel
 
What about the popup motd type pannels? Is there any way to create and control one of those?

Chdata 10-30-2014 22:36

Re: Advanced ShowMOTDPanel
 
Maybe big motd IS the popup type panel?

Dr. McKay 10-30-2014 23:33

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Chdata (Post 2218212)
Maybe big motd IS the popup type panel?

It's not.

friagram 11-03-2014 09:43

Re: Advanced ShowMOTDPanel
 
You talking about the info text panels that open vgui panels behind the ui, like console style?
You make those similar to the upper left admin say (whatever its called), just change the message type.

zeroibis 11-04-2014 13:08

Re: Advanced ShowMOTDPanel
 
No I am talking about the full on html popup windows that you get if you were to click on a link with target_blank for example.

Dr. McKay 06-29-2015 00:19

Re: Advanced ShowMOTDPanel
 
Updated for transitional syntax.

DJ Data 09-14-2015 12:44

Re: Advanced ShowMOTDPanel
 
Very well done, thanks for keeping the 1.6 code in there :)

fragnichtnach 02-07-2016 06:32

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Dr. McKay (Post 2078857)
I haven't actually tested this in-game, but it should work fine.

This is an enhanced version of ShowMOTDPanel that allows for:
  • Hidden MOTD panels
  • Big MOTD panel (in TF2)
  • Verification that the client can actually receive MOTD panels before sending it
Example:

PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <advanced_motd>

public void OnPluginStart() {
    
RegConsoleCmd("sm_google"Command_Google"Opens Google in a large MOTD window");
}

public 
Action Command_Google(int clientint args) {
    
AdvMOTD_ShowMOTDPanel(client"Google""http://www.google.com"MOTDPANEL_TYPE_URLtruetruetrueOnMOTDFailure);
    return 
Plugin_Handled;
}

public 
void OnMOTDFailure(int clientMOTDFailureReason reason) {
    if(
reason == MOTDFailure_Disabled) {
        
PrintToChat(client"[SM] You have HTML MOTDs disabled.");
    } else if(
reason == MOTDFailure_Matchmaking) {
        
PrintToChat(client"[SM] You cannot view HTML MOTDs because you joined via Quickplay.");
    } else if(
reason == MOTDFailure_QueryFailed) {
        
PrintToChat(client"[SM] Unable to verify that you can view HTML MOTDs.");
    } else {
        
PrintToChat(client"[SM] Unable to verify that you can view HTML MOTDs for an unknown reason.");
    }



I have tested it in CS:GO.
Plugin is loaded (sm plugins ->"example.smx" example.smx).
Modt does not show.
There is no errormessage!

I don't think it is working at the moment.

I used this because I've go problems with ShowMOTDPanel. As well nothing was opening with this command. (I have clientsided cl_disablehtmlmotd 0.)

Is there actually a problem with opening the motd out of running game?

fragnichtnach 02-09-2016 00:48

Re: Advanced ShowMOTDPanel
 
I read somewhere else: "The latest steam client update broke the webkit in-game for anything other than initial page hit"
Is this The Problem?

Mitchell 02-11-2016 10:25

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by fragnichtnach (Post 2391312)
I read somewhere else: "The latest steam client update broke the webkit in-game for anything other than initial page hit"
Is this The Problem?

the original motd panel has never worked in csgo.

You9 04-29-2016 21:57

Re: Advanced ShowMOTDPanel
 
It's should work in CS:GO?
Because the default ShowMOTDPanel working, but AdvMOTD_ShowMOTDPanel not working :( No errors or something, validate enabled and stuff.

nosoop 08-11-2017 04:55

Re: Advanced ShowMOTDPanel
 
1 Attachment(s)
The transitional syntax version of AdvMOTD_OnQueryFinished function isn't completing the callback with Call_Finish(). It always fails silently. The pretransitional one is fine, on the other hand.

Here's a fixed copy that actually completes the call and removes the forward instantiation in favor of just packing in the function.

Code:

#if defined _advmotd_enabled
 #endinput
#endif
#define _advmotd_enabled

enum MOTDFailureReason {
        MOTDFailure_Unknown, // Failure reason unknown
        MOTDFailure_Disabled, // Client has explicitly disabled HTML MOTDs
        MOTDFailure_Matchmaking, // HTML MOTD is disabled by Quickplay/matchmaking (TF2 only)
        MOTDFailure_QueryFailed // cl_disablehtmlmotd convar query failed
};

typedef MOTDFailure = function void (int client, MOTDFailureReason reason);

/**
 * Displays an MOTD panel to a client with advanced options
 *
 * @param client                Client index the panel should be shown to
 * @param title                        Title of the MOTD panel (not displayed on all games)
 * @param msg                        Content of the MOTD panel; could be a URL, plain text, or a stringtable index
 * @param type                        Type of MOTD this is, one of MOTDPANEL_TYPE_TEXT, MOTDPANEL_TYPE_INDEX, MOTDPANEL_TYPE_URL, MOTDPANEL_TYPE_FILE
 * @param visible                Whether the panel should be shown to the client
 * @param big                        true if this should be a big MOTD panel (TF2 only)
 * @param verify                true if we should check if the client can actually receive HTML MOTDs before sending it, false otherwise
 * @param callback                A callback to be called if we determine that the client can't receive HTML MOTDs
 * @noreturn
 */
stock void AdvMOTD_ShowMOTDPanel(int client, const char[] title, const char[] msg, int type=MOTDPANEL_TYPE_INDEX, bool visible=true, bool big=false, bool verify=false, MOTDFailure callback=INVALID_FUNCTION) {
        char connectmethod[32];
        if(verify && GetClientInfo(client, "cl_connectmethod", connectmethod, sizeof(connectmethod))) {
                if(StrContains(connectmethod, "quickplay", false) != -1 || StrContains(connectmethod, "matchmaking", false) != -1) {
                        if(callback != INVALID_FUNCTION) {
                                Call_StartFunction(null, callback);
                                Call_PushCell(client);
                                Call_PushCell(MOTDFailure_Matchmaking);
                                Call_Finish();
                        }
                        return;
                }
        }
       
        KeyValues kv = new KeyValues("data");
        kv.SetString("title", title);
        kv.SetNum("type", type);
        kv.SetString("msg", msg);
        if(big) {
                kv.SetNum("customsvr", 1);
        }
       
        if(verify) {
                DataPack pack = new DataPack();
                pack.WriteCell(kv);
                pack.WriteCell(visible);
                pack.WriteFunction(callback);
               
                QueryClientConVar(client, "cl_disablehtmlmotd", AdvMOTD_OnQueryFinished, pack);
        } else {
                ShowVGUIPanel(client, "info", kv, visible);
                CloseHandle(kv);
        }
}

public void AdvMOTD_OnQueryFinished(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, DataPack pack) {
        pack.Reset();
        KeyValues kv = pack.ReadCell();
        bool visible = pack.ReadCell();
        Function callback = pack.ReadFunction();
        delete pack;
       
        if(result != ConVarQuery_Okay || StringToInt(cvarValue)) {
                delete kv;
               
                if(callback != INVALID_FUNCTION) {
                        Call_StartFunction(INVALID_HANDLE, callback);
                        Call_PushCell(client);
                        Call_PushCell((result != ConVarQuery_Okay) ? MOTDFailure_QueryFailed : MOTDFailure_Disabled);
                        Call_Finish();
                }
                return;
        }
       
        ShowVGUIPanel(client, "info", kv, visible);
        delete kv;
}


Dragokas 02-17-2018 20:10

Re: Advanced ShowMOTDPanel
 
Is MOTD support callbacks like if I would like to receive an event when flash player finished playing the music?

I am using Disco plugin.
And I don't like it looping the track instead of playing tracklist.

So, first solution is to modify php such a way it close web-page as soon as track is finished playing. I hope MOTD has ability to track such event and return a callback. So, I can jump to next track via SourceMod plugin.

Second solution, of course, add tracklist support to php or swf player, but I'm not very familiar with php or Action Script.

Of course, there is always 3-rd variant: make script for auto-calculating each song length and save it into .cfg, so plugin will use it to track end of each song.

nosoop 02-18-2018 03:20

Re: Advanced ShowMOTDPanel
 
Quote:

Originally Posted by Dragokas (Post 2578770)
Is MOTD support callbacks like if I would like to receive an event when flash player finished playing the music?

I am using Disco plugin.
And I don't like it looping the track instead of playing tracklist.

[...]

Nope; as far as I can tell a page can't make the client send callback actions by itself.

For your particular use case, you could write something up with WebSockets for client-server comms, but assuming you had control over your web server stack, your best bet would be to deliver a stream of audio using some HTTP streaming application so it's mostly synced across clients, then use a minimal amount of HTML to source and playback the audio (and you can show playlist info by passing data from your streaming server to your game server).


All times are GMT -4. The time now is 16:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.