This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 26th, 2012  |  syntax: C++  |  size: 1.11 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data