chatcommand_simplegameusers.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "chatcommand_simplegameusers.h"
  2. #include "websocket.h"
  3. #include "datastring.h"
  4. #include "parameters.h"
  5. #include "stringbuilder.h"
  6. #include "message.h"
  7. #include "Debug.h"
  8. #include <inttypes.h>
  9. #include "simplechatgame.h"
  10. // simplegameusers(messageid,gameid)
  11. // Returns the list of users in a game. Returns a simplegameusers message or an error message.
  12. bool chatcommand_simplegameusers::processmessage(char first_letter,message *received_message,chatclient *client)
  13. {
  14. if ((first_letter != 's')
  15. || (received_message->actual_message.substr(0,16)!="simplegameusers(")) {
  16. return false;
  17. }
  18. Debug debug(__FILE__,__func__,__LINE__);
  19. message *new_message;
  20. datastring method_parameters;
  21. parameters parameters_parsed;
  22. bool parameter_success = true;
  23. int64_t messageid;
  24. datastring gameid;
  25. biglist_item<simplechatgame *> *gamesearch;
  26. simplechatgame *game;
  27. datastring error_message;
  28. debug = __LINE__;
  29. method_parameters = received_message->actual_message.substr(16,received_message->actual_message.length-17);
  30. method_parameters.null_terminate(); // Used to comply with snprintf.
  31. parameters_parsed.long_parameter(method_parameters,parameter_success);
  32. parameters_parsed.string_parameter(method_parameters,parameter_success);
  33. debug = __LINE__;
  34. if (parameter_success) {
  35. // Give the parameters nice names.
  36. debug = __LINE__;
  37. messageid = parameters_parsed.long_parameters[0];
  38. gameid = parameters_parsed.string_parameters[1];
  39. debug = __LINE__;
  40. // Find the game.
  41. gamesearch = the_websocket->find_simple_game(gameid);
  42. if (gamesearch == nullptr) {
  43. error_message = "That gameid was not found.";
  44. error(client,error_message,messageid);
  45. return true;
  46. }
  47. game = gamesearch->item;
  48. debug = __LINE__;
  49. new_message = simplegameusers(messageid,gameid,&(game->users));
  50. client->push_message(&new_message);
  51. debug = __LINE__;
  52. } else {
  53. debug = __LINE__;
  54. parameters_not_correct(client,received_message);
  55. }
  56. debug = __LINE__;
  57. return true;
  58. }