Advertisement
Guest User

Untitled

a guest
Feb 26th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1.  
  2. //this should be already implemented
  3. char tolower(char ch)
  4. {
  5.  if(ch>='A'&&ch<='Z')
  6.   return ch-('A'-'a');
  7.  return ch;
  8. }
  9.  
  10. //compare strings ignoring case
  11. int stricmp(const char *a, const char *b)
  12. {
  13.  int i;
  14.  for(i=0;;i++)
  15.  {
  16.   if(tolower(a[i])!=tolower(b[i]))
  17.    return i;
  18.   if((!a[i]&&b[i])||(a[i]&&!b[i]))
  19.    return i;
  20.  }
  21.  return 0;
  22. }
  23.  
  24. typedef struct
  25. {
  26.  char *name;
  27.  int args;
  28.  void (*cmd)(ePlayerNetID *p);
  29. } svcmd_t;
  30.  
  31. void command1_f(ePlayerNetID *p)
  32. {
  33.  std::cout << "command1 called with argument " << tok_argv(1) << std::endl;
  34. }
  35.  
  36. void command2_f(ePlayerNetID *p)
  37. {
  38.  std::cout << "command2 called" << std::endl;
  39. }
  40.  
  41. const svcmd_t svcmds[]=
  42. {
  43.  {"command1", 1, command1_f},
  44.  {"command2", 0, command2_f}
  45. };
  46.  
  47. static bool handle_cmds(const char *input, ePlayerNetID *p)
  48. {
  49.  int i;
  50.  
  51.  if(input[0]!='/')
  52.   return false;
  53.  
  54.  toTokenize(input+1);
  55.  if(tok_argc()==0)
  56.   return false; //wtf?
  57.  
  58.  for(i=0;i<sizeof(svcmds)/sizeof(svcmd_t);i++)
  59.   if(tok_argc()>=svcmds[i].args)
  60.    if(!stricmp(tok_argv(0),svcmds[i].name))
  61.    {
  62.     svcmds[i].cmd(p);
  63.     return true;
  64.    }
  65.  return false;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement