123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- #include "chatcommand.h"
- #include "stringbuilder.h"
- #include "message.h"
- #include "datastring.h"
- #include <stdio.h>
- #include <inttypes.h>
- #include "Debug.h"
- message *chatcommand::fromstringbuilder(stringbuilder &output)
- {
- // Converts a stringbuilder to a message object.
- message *new_message;
- new_message = new message();
- *new_message = output;
- return new_message;
- }
- void chatcommand::incorrect_system_password(chatclient *client,int64_t messageid)
- {
- message *new_message;
- stringbuilder output;
-
- output += "error(26,Incorrect system password";
- output += messageid;
- output += ")";
- new_message = new message();
- *new_message = output;
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- return;
- }
- void chatcommand::success_message(chatclient *client,int64_t messageid)
- {
- stringbuilder output;
- message *new_message;
- new_message = new message();
- output += "success(";
- output += messageid;
- output += ")";
- *new_message = output;
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- return;
- }
- void chatcommand::not_implemented(chatclient *client)
- {
- client->add_message("error(36,That command is not yet implemented.0)");
- client->callback_on_writable();
- return;
- }
- void chatcommand::parameters_not_correct(chatclient *client,message *received_message)
- {
- stringbuilder output;
- message *new_message;
- output += "erorr(";
- output += (45+received_message->actual_message.length);
- output += ",";
- output += "Syntax error in parameters. Original message:";
- output += received_message->actual_message;
- output += "0)";
- new_message = fromstringbuilder(output);
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- return;
- }
- void chatcommand::message_not_understood(chatclient *client,datastring bad_message)
- {
- stringbuilder output;
- message *new_message;
- output += "error(";
- output += (bad_message.length + 32);
- output += ",That message was not understood:";
- output += bad_message;
- output += "0)";
- new_message = fromstringbuilder(output);
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- return;
- }
- void chatcommand::error(chatclient *client,datastring error_message,int64_t messageid)
- {
- message *new_message;
- stringbuilder output;
- new_message = new message();
- output += "error(";
- output.addparameter(error_message);
- output += messageid;
- output +=")";
-
- *new_message = output;
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- }
- void chatcommand::error(chatclient *client,datastring error_message)
- {
- stringbuilder output;
- message *new_message;
- output += "error(";
- output.addparameter(error_message);
- output +="0)";
- new_message = new message();
- *new_message = output;
- client->add_message(new_message);
- idisposable::dereference((idisposable**)&new_message);
- client->callback_on_writable();
- }
- message *chatcommand::userjoinedchatroom(
- int64_t messageid,int64_t chatroomid,int64_t chatclientid, user *new_user)
- {
- stringbuilder output;
- output += "userjoinedchatroom(";
- output.addparameter(messageid);
- output.addparameter(chatroomid);
- output.addparameter(chatclientid);
- if (new_user == nullptr) {
- output += "0,0,";
- } else {
- output.addparameter(new_user->userid);
- output.addparameter(*new_user->username);
- }
- output += ")";
- return fromstringbuilder(output);
- }
- message *chatcommand::userleftchatroom(int64_t messageid,int64_t chatroomid, int64_t chatclientid, user *old_user)
- {
- stringbuilder output;
- output += "userleftchatroom(";
- output.addparameter(messageid);
- output.addparameter(chatroomid);
- if (old_user == nullptr) {
- output += "0,0,";
- } else {
- output.addparameter(old_user->userid);
- output.addparameter(*old_user->username);
- }
- output += ")";
- return fromstringbuilder(output);
- }
- message *chatcommand::chatroomwasdeleted(int64_t messageid,int64_t chatroomid)
- {
- Debug debug(__FILE__,__func__,__LINE__);
- message *new_message;
- stringbuilder output;
-
- output += "chatroomwasdeleted(";
- debug = __LINE__;
- output.addparameter(messageid);
- debug = __LINE__;
- output.addparameter(chatroomid);
- debug = __LINE__;
- output += ")";
- debug = __LINE__;
- return fromstringbuilder(output);
- }
- message *chatcommand::chatroomcreated(int64_t messageid,int64_t chatroomid,datastring room_name,int info)
- {
- stringbuilder output_message;
- output_message += "chatroomcreated(";
- output_message.addparameter(messageid);
- output_message.addparameter(chatroomid);
- output_message.addparameter(room_name);
- output_message.addparameter(info);
- output_message += ")";
-
- return fromstringbuilder(output_message);
- }
- message *chatcommand::yourchatclientid(int64_t chatclientid)
- {
- stringbuilder output_message;
- output_message += "yourchatclientid(";
- output_message.addparameter(chatclientid);
- output_message += ")";
-
- return fromstringbuilder(output_message);
- }
- message *chatcommand::chat(int64_t messageid,int64_t chatroomid
- ,int64_t chatclientid,int64_t userid,datastring message_to_send)
- {
- stringbuilder output_message;
-
- output_message += "chat(";
- output_message.addparameter(messageid);
- output_message.addparameter(chatroomid);
- output_message.addparameter(chatclientid);
- output_message.addparameter(userid);
- output_message.addparameter(message_to_send);
- output_message += ")";
-
- return fromstringbuilder(output_message);
- }
- message *chatcommand::msg(int64_t messageid
- ,int64_t chatclientid,int64_t userid,datastring message_to_send)
- {
- stringbuilder output_message;
- output_message += "msg(";
- output_message.addparameter(messageid);
- output_message.addparameter(chatclientid);
- output_message.addparameter(userid);
- output_message.addparameter(message_to_send);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegamestarted(int64_t messageid,datastring gameid)
- {
- stringbuilder output_message;
- output_message += "simplegamestarted(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
-
- message *chatcommand::simplegamedata(int64_t messageid,datastring gameid,datastring username,datastring gamedata)
- {
- stringbuilder output_message;
- output_message += "simplegamedata(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message.addparameter(username);
- output_message.addparameter(gamedata);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegameleave(int64_t messageid,datastring gameid,datastring username,datastring gamedata)
- {
- stringbuilder output_message;
- output_message += "simplegameleave(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message.addparameter(username);
- output_message.addparameter(gamedata);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegamechat(int64_t messageid,datastring gameid,datastring username,datastring chatmessage)
- {
- stringbuilder output_message;
- output_message += "simplegamechat(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message.addparameter(username);
- output_message.addparameter(chatmessage);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegamejoined(int64_t messageid,datastring gameid,datastring gamedata,biglist<simplechatgameuser *> *userlist)
- {
- stringbuilder output_message;
- datastring upordown;
- output_message += "simplegamejoined(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message.addparameter(gamedata);
-
- biglist_iterator<simplechatgameuser *>userloop(userlist);
- while (!userloop.eof()) {
- output_message.addparameter(*(userloop.item->username));
- upordown = userloop.item->client == nullptr ? "Down" : "Up";
- output_message.addparameter(upordown);
- userloop.movenext();
- }
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegameusers(int64_t messageid,datastring gameid,biglist<simplechatgameuser *> *userlist)
- {
- stringbuilder output_message;
- output_message += "simplegameusers(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- datastring upordown;
- if (userlist != nullptr) {
- biglist_iterator<simplechatgameuser *>userloop(userlist);
- while (!userloop.eof()) {
- output_message.addparameter(*(userloop.item->username));
- upordown = userloop.item->client == nullptr ? "Down" : "Up";
- output_message.addparameter(upordown);
- userloop.movenext();
- }
- }
- output_message += ")";
- return fromstringbuilder(output_message);
- }
- message *chatcommand::simplegameuserdata(int64_t messageid,datastring gameid,datastring username,datastring userdata)
- {
- // A message listing the user data for a user in a game.
- stringbuilder output_message;
- output_message += "simplegameuserdata(";
- output_message.addparameter(messageid);
- output_message.addparameter(gameid);
- output_message.addparameter(username);
- output_message.addparameter(userdata);
- output_message += ")";
- return fromstringbuilder(output_message);
- }
|