alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
499 stars 203 forks source link

Can show_motd not replace ServerName custom message? #872

Open metita opened 4 years ago

metita commented 4 years ago

Not sure if this is intended or a unexpected behavior but when calling ServerName message and editing it to display a custom one, when calling show_motd that custom message will get replaced with the original hostname, not sure if this should work like that but I think that should be addressed if possible. (Unless it's something client-side).

SmileYzn commented 4 years ago

motd function always will show hostname by default if string for title is empty i guess

metita commented 4 years ago

motd function always will show hostname by default if string for title is empty i guess

String empty or not it will get replaced.

SmileYzn commented 4 years ago

Did you have an test case code?

You calling ServerName and trying to display a motd?

metita commented 4 years ago

If you set a custom ServerName hooking the message, once you open a motd , that value will get replaced with default servername, thats all.

SmileYzn commented 4 years ago

https://github.com/alliedmodders/amxmodx/blob/c86813697acf3a3b577ca35426053db8dd7f8902/amxmodx/util.cpp#L66

UTIL_ShowMOTD uses ServerName Message, look at the begin and end of function. Since MOTD messages aways display a serverName, what amxx team do is send ServerName message with motd title by show_motd param. And at the end send's the original hostname on ServerName message.

Now i have sure that you need to do something to avoid that on ServerName message hook. Or just show a code example of how you hook in ServerName message.

metita commented 4 years ago

There should be a way from the native itself to not hook ServerName it is quite annoying, literally you need a permanent task that set the custom ServerName and that will do the work, but thats not a great idea.

metita commented 4 years ago

It is a simple thing what I do.

register_message( get_user_msgid( "ServerName" ), "OnServerName" );

public OnServerName( )
{
    set_msg_arg_string( 1, "Hi" );
}
SmileYzn commented 4 years ago

ServerName message is fine, i think it is related wth this?

https://forums.alliedmods.net/showthread.php?t=114873

Sinte this change string itself, also you can try to compare with hostname cvar

metita commented 4 years ago

ServerName message is fine, i think it is related wth this?

https://forums.alliedmods.net/showthread.php?t=114873

Sinte this change string itself, also you can try to compare with hostname cvar

Not sure if that will works, if show_motd gets executed, ServerName will restore his default value, nothing will change AFAIK.

SmileYzn commented 4 years ago

I guess when amxmodx call ServerName messages this is not reflected on registered message, so this is buggy. This is the real problem.

A solution is a pull request to call message.

EDIT: You can try to call show_motd function, after that call ServerName with your string. I have sure that will solve this problem.

metita commented 4 years ago

No, I don't think that will do the work, each call of show_motd will replace ServerName on client-side regardless of execution. This is a common unexpected behavior I guess, many friends have the same problem and are using or a permanent set_task or avoiding the usage of show_motd, my mod at least calls show_motd many times because there is a menu which explains concepts/rules of my mod.

SmileYzn commented 4 years ago

In each call to show_motd need to call ServerName message to avoid that, or you do in your code, or a future fix from amxx team will do in their code. Anyway i will try to make a pull request later to change this.

Ps. This is already made in amxmodx util code, but using hostname instead of old name at the message.

metita commented 4 years ago

Yeah, that may be a good solution, save ServerName changed value somewhere (like cache?) and then restoring it once show_motd gets displayed.

@Arkshine any insight?