1 #ifndef _NETWORK_CMD_H_ 2 #define _NETWORK_CMD_H_ 3 4 #include "../simtypes.h" 5 #include "../tpl/slist_tpl.h" 6 #include "../tpl/vector_tpl.h" 7 #include "network.h" 8 #include "pwd_hash.h" 9 10 class address_list_t; 11 class karte_t; 12 class packet_t; 13 class socket_info_t; 14 15 // actual commands 16 enum { 17 NWC_INVALID = 0, 18 NWC_GAMEINFO, 19 NWC_NICK, 20 NWC_CHAT, 21 NWC_JOIN, 22 NWC_SYNC, 23 NWC_GAME, 24 NWC_READY, 25 NWC_TOOL, 26 NWC_CHECK, 27 NWC_PAKSETINFO, 28 NWC_SERVICE, 29 NWC_AUTH_PLAYER, 30 NWC_CHG_PLAYER, 31 NWC_SCENARIO, 32 NWC_SCENARIO_RULES, 33 NWC_STEP, 34 NWC_COUNT 35 }; 36 37 class network_command_t { 38 protected: 39 packet_t *packet; 40 // always send: 41 uint16 id; 42 uint32 our_client_id; 43 // ready for sending 44 bool ready; 45 public: 46 network_command_t(uint16 /*id*/); 47 network_command_t(); 48 virtual ~network_command_t(); 49 // receive: calls rdwr from packet 50 // return true on success 51 bool receive(packet_t *p); 52 // calls rdwr if packet is empty 53 void prepare_to_send(); 54 /** 55 * sends to a client 56 * sends complete command-packet 57 * @return whether send was successful 58 */ 59 bool send(SOCKET s); 60 61 // write our data to the packet 62 virtual void rdwr(); 63 64 // executes the command 65 // (see network_world_command_t::execute() ) 66 // if returns true this can be deleted afterwards execute(karte_t *)67 virtual bool execute(karte_t *) { return true;} 68 get_name()69 virtual const char* get_name() { return "network_command_t";} 70 get_id()71 uint16 get_id() { return id;} 72 73 SOCKET get_sender(); 74 get_packet()75 packet_t *get_packet() const { return packet; } 76 /** 77 * returns ptr to a copy of the packet 78 */ 79 packet_t *copy_packet() const; 80 81 // creates an instance: 82 // gets the nwc-id from the packet, and reads its data 83 static network_command_t* read_from_packet(packet_t *p); 84 }; 85 86 87 /** 88 * base class for any service commands 89 */ 90 class nwc_service_t : public network_command_t { 91 public: 92 uint32 flag; 93 94 enum { 95 SRVC_LOGIN_ADMIN = 0, 96 SRVC_ANNOUNCE_SERVER = 1, 97 SRVC_GET_CLIENT_LIST = 2, 98 SRVC_KICK_CLIENT = 3, 99 SRVC_BAN_CLIENT = 4, 100 SRVC_GET_BLACK_LIST = 5, 101 SRVC_BAN_IP = 6, 102 SRVC_UNBAN_IP = 7, 103 SRVC_ADMIN_MSG = 8, 104 SRVC_SHUTDOWN = 9, 105 SRVC_FORCE_SYNC = 10, 106 SRVC_GET_COMPANY_LIST = 11, 107 SRVC_GET_COMPANY_INFO = 12, 108 SRVC_UNLOCK_COMPANY = 13, 109 SRVC_REMOVE_COMPANY = 14, 110 SRVC_LOCK_COMPANY = 15, 111 SRVC_MAX 112 }; 113 114 uint32 number; 115 char *text; 116 vector_tpl<socket_info_t*> *socket_info; 117 address_list_t *address_list; 118 nwc_service_t()119 nwc_service_t() : network_command_t(NWC_SERVICE), text(NULL), socket_info(NULL), address_list(NULL) { } 120 ~nwc_service_t(); 121 122 #ifndef NETTOOL 123 bool execute(karte_t *) OVERRIDE; 124 #endif 125 126 void rdwr() OVERRIDE; 127 get_name()128 const char* get_name() OVERRIDE { return "nwc_service_t";} 129 }; 130 131 132 /** 133 * nwc_auth_player_t 134 * @from-client: client sends password hash to unlock player / set player password 135 * server sends nwc_auth_player_t to sender 136 * @from-server: 137 * information whether players are locked / unlocked 138 */ 139 class nwc_auth_player_t : public network_command_t { 140 public: nwc_auth_player_t()141 nwc_auth_player_t() : network_command_t(NWC_AUTH_PLAYER), hash(), player_unlocked(0), player_nr(255) { } nwc_auth_player_t(uint8 nr,const pwd_hash_t & hash_)142 nwc_auth_player_t(uint8 nr, const pwd_hash_t& hash_) : network_command_t(NWC_AUTH_PLAYER), hash(hash_), player_unlocked(0), player_nr(nr) { } 143 144 #ifndef NETTOOL 145 bool execute(karte_t *) OVERRIDE; 146 #endif 147 void rdwr() OVERRIDE; get_name()148 const char* get_name() OVERRIDE { return "nwc_auth_player_t";} 149 pwd_hash_t hash; 150 uint16 player_unlocked; 151 uint8 player_nr; 152 153 /** 154 * sets unlocked flags for playing at server 155 */ 156 static void init_player_lock_server(karte_t *); 157 }; 158 159 #endif 160