1

Topic: Chat function

Hello world ^^

I decided to create account system for some my mods on 0.6.0 tw version. Client should to write in chat "/register his_login his_password" for register.
Problem: message "/register login password" is shown in public chat.
Question: How to hide this message? What i should to add in?
Code:

if(sscanf(pMsg->m_pMessage, "/register %s %s", login, password) != 2)
        {


            SendChatTarget(ClientID, "Please stick to the given structure:");
            SendChatTarget(ClientID, "/register <login> <password>");


        }

        else
        {


              registration(login, password);

        }

Thanks.

2

Re: Chat function

We need to know where you've put your code to tell you. I guess it is in some chat function, so a return; wil probably do the trick for you.

Not Luck, Just Magic.

3 (edited by WrX 2011-07-03 18:47:21)

Re: Chat function

Dune wrote:

We need to know where you've put your code to tell you. I guess it is in some chat function, so a return; wil probably do the trick for you.

I have put that code to "gamecontext.cpp" in "void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)"  function (572 line). It is "clean" sources of teeworlds. This problem in "sscanf" function i guess but i can't catch her :<

Note: if i use "str_comp_nocase(pMsg->m_pMessage, "/info")" - it is works very well, but it is doesn't work with arguments like "login" and "password".

4

Re: Chat function

WrX wrote:
Dune wrote:

We need to know where you've put your code to tell you. I guess it is in some chat function, so a return; wil probably do the trick for you.

I have put that code to "gamecontext.cpp" in "void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)"  function (572 line). It is "clean" sources of teeworlds. This problem in "sscanf" function i guess but i can't catch her :<

Note: if i use "str_comp_nocase(pMsg->m_pMessage, "/info")" - it is works very well, but it is doesn't work with arguments like "login" and "password".

Did you read the second sentence? Just put a return; the function will stop there.

Not Luck, Just Magic.

5 (edited by WrX 2011-07-03 19:31:59)

Re: Chat function

Dune wrote:

Did you read the second sentence? Just put a return; the function will stop there.

Sorry.
This function wasn't declared in teeworlds sources, so i don't know her content&return value.
I just know that she has been declared in stdio.h file which my pc didn't find.

6 (edited by Dune 2011-07-03 19:57:15)

Re: Chat function

WrX wrote:
Dune wrote:

Did you read the second sentence? Just put a return; the function will stop there.

Sorry.
This function wasn't declared in teeworlds sources, so i don't know her content&return value.
I just know that she has been declared in stdio.h file which my pc didn't find.

Wow, it's weird how you just can't understand that, it's so simple... Just add a "return;" in the function where you're adding this code to stop the message from being sent to all the players from the server.

Not Luck, Just Magic.

7

Re: Chat function

Problem fixed. This problem wasn't in 'return'. She was in 'strncmp' function.

8

Re: Chat function

Yea... true, problemes are always female:

WrX wrote:

She was in 'strncmp' function.

» Use the Search Function before opening multiple topics...
» Member of: JsA - Just stay Alloha! (since 2009)

9

Re: Chat function

WrX wrote:

Problem fixed. This problem wasn't in 'return'. She was in 'strncmp' function.

Don't use strncmp, use str_comp_num which is provided by system.h.

10

Re: Chat function

heinrich5991 wrote:
WrX wrote:

Problem fixed. This problem wasn't in 'return'. She was in 'strncmp' function.

Don't use strncmp, use str_comp_num which is provided by system.h.

Reason? Just wanna to know. It is works with strncmp very well too.

11

Re: Chat function

WrX wrote:
heinrich5991 wrote:
WrX wrote:

Problem fixed. This problem wasn't in 'return'. She was in 'strncmp' function.

Don't use strncmp, use str_comp_num which is provided by system.h.

Reason? Just wanna to know. It is works with strncmp very well too.

system.h provides a lot of function to replace the string.h, so you definitely should not use this include from the standard library, and prefer the functions you already have at your disposal :)

Not Luck, Just Magic.