sources/network/rconsession.cpp

changeset 13
09dcaeaa216b
parent 12
8d0d1b368de0
child 14
33b8f428bacb
equal deleted inserted replaced
12:8d0d1b368de0 13:09dcaeaa216b
86 // 86 //
87 METHOD 87 METHOD
88 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void 88 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void
89 { 89 {
90 print ("Processing packet of %1 bytes\n", packet.written_length()); 90 print ("Processing packet of %1 bytes\n", packet.written_length());
91 bool ok = true; 91
92 92 try
93 while (packet.bytes_left() > 0) 93 {
94 { 94 while (packet.bytes_left() > 0)
95 int header = packet.read_byte (&ok); 95 {
96 print ("Recieved packet with header %1\n", header); 96 int header = packet.read_byte();
97 97 print ("Recieved packet with header %1\n", header);
98 switch (ServerResponse (header)) 98
99 { 99 switch (ServerResponse (header))
100 case SVRC_OLDPROTOCOL:
101 print ("wrong version\n");
102 m_state = RCON_DISCONNECTED;
103 break;
104
105 case SVRC_BANNED:
106 print ("you're banned\n");
107 m_state = RCON_DISCONNECTED;
108 break;
109
110 case SVRC_SALT:
111 { 100 {
112 String salt = packet.read_string(); 101 case SVRC_OLDPROTOCOL:
113 m_salt = salt; 102 print ("wrong version\n");
114 m_state = RCON_AUTHENTICATING; 103 m_state = RCON_DISCONNECTED;
115 send_password(); 104 break;
105
106 case SVRC_BANNED:
107 print ("you're banned\n");
108 m_state = RCON_DISCONNECTED;
109 break;
110
111 case SVRC_SALT:
112 {
113 String salt = packet.read_string();
114 m_salt = salt;
115 m_state = RCON_AUTHENTICATING;
116 send_password();
117 }
118 break;
119
120 case SVRC_INVALIDPASSWORD:
121 print ("bad password\n");
122 m_state = RCON_DISCONNECTED;
123 break;
124
125 case SVRC_MESSAGE:
126 {
127 String message = packet.read_string();
128 if (message.ends_with ("\n"))
129 message.remove_from_end (1);
130 print ("message: %1\n", message);
131 }
132 break;
133
134 case SVRC_LOGGEDIN:
135 print ("login successful\n");
136 m_serverProtocol = packet.read_byte();
137 m_hostname = packet.read_string();
138 m_state = RCON_CONNECTED;
139
140 for (int i = packet.read_byte(); i > 0; --i)
141 process_server_updates (packet);
142
143 for (int i = packet.read_byte(); i > 0; --i)
144 {
145 String message = packet.read_string();
146 message.normalize();
147 print ("--- %1\n", message);
148 }
149 break;
150
151 case SVRC_UPDATE:
152 process_server_updates (packet);
153 break;
116 } 154 }
117 break; 155 }
118 156 }
119 case SVRC_INVALIDPASSWORD: 157 catch (std::exception& e)
120 print ("bad password\n"); 158 {
121 m_state = RCON_DISCONNECTED; 159 print ("error while reading packet: %1\n", e.what());
122 break;
123
124 case SVRC_MESSAGE:
125 {
126 String message = packet.read_string();
127 if (message.ends_with ("\n"))
128 message.remove_from_end (1);
129 print ("message: %1\n", message);
130 }
131 break;
132
133 case SVRC_LOGGEDIN:
134 print ("login successful\n");
135 m_serverProtocol = packet.read_byte();
136 m_hostname = packet.read_string();
137 m_state = RCON_CONNECTED;
138
139 for (int i = packet.read_byte(); i > 0; --i)
140 process_server_updates (packet);
141
142 for (int i = packet.read_byte(); i > 0; --i)
143 {
144 String message = packet.read_string();
145 message.normalize();
146 print ("--- %1\n", message);
147 }
148
149 break;
150
151 case SVRC_UPDATE:
152 process_server_updates (packet);
153 break;
154 }
155
156 if (not ok)
157 print ("error while reading packet\n");
158 } 160 }
159 } 161 }
160 162
161 METHOD 163 METHOD
162 RCONSession::process_server_updates (Bytestream& packet) -> void 164 RCONSession::process_server_updates (Bytestream& packet) -> void

mercurial