1 (edited by Ikaron 2012-03-24 14:50:46)

Topic: [Help] Chat-Command-Registering and Argument-parsing

Hello, and sorry for posting again so soon, but I've come to another problem... Well, actually 2 questions.
So, first, where is teeworlds command-parsing done? I could add mine in onMessage, but is there a more convenient/beautiful way to do this?
My second question is, how do you split a text by a certain regex? In java you would do it like that;

"Hello, world! It's me!".split(" ");

//returns String[]:
// {"Hello,", "world!", "It's", "me!"}

How would you do that in c++?
Thanks in advance,
Ikaron

2

Re: [Help] Chat-Command-Registering and Argument-parsing

Ikaron wrote:

So, first, where is teeworlds command-parsing done?

It depends on what you are trying to do. Take a look at src/game/variables.h ... if you would do something like that (e.g. cl_showfps or sv_timeout) then you have to add it here. Keep in mind that the usage in the *.cpp files would differ so some SvTimeout in variables.h would be some m_SvTimeout afterwards (used via g_Config.m_SvTimeout). But you can't add that way some functions for the client that should work afterwards on the server (means if you add some cl_blabla... would only work if users are using your client).

If you would give the client the possibility to do some stuff on the server (e.g. show some info or cycle weapon or whatever) with the standard-TW-client you can do with a workaround in the "OnMessage" function in src/game/server/gamecontext.cpp.

if(pMsg->m_pMessage[0] == '/' && m_pController && (str_comp(m_pController->m_pGameType,"MOD") == 0)
{
  if((!str_comp_nocase(pMsg->m_pMessage,"/info")) || (!str_comp_nocase(pMsg->m_pMessage, "/help")))
  {
    SendChatTarget(ClientID, "Mymod info version ... blabla");
    return;
  }
}

Regarding your second question. Probably take a look here: http://www.cplusplus.com/reference/clib … ng/strtok/

3

Re: [Help] Chat-Command-Registering and Argument-parsing

thank you kindly smile