| 1191 | } |
| 1192 | |
| 1193 | NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet &p) |
| 1194 | { |
| 1195 | if (this->status < STATUS_AUTHORIZED) { |
| 1196 | /* Illegal call, return error and ignore the packet */ |
| 1197 | return this->SendError(NETWORK_ERROR_NOT_AUTHORIZED); |
| 1198 | } |
| 1199 | |
| 1200 | uint32_t frame = p.Recv_uint32(); |
| 1201 | |
| 1202 | Debug(net, 9, "client[{}] Receive_CLIENT_ACK(): frame={}", this->client_id, frame); |
| 1203 | |
| 1204 | /* The client is trying to catch up with the server */ |
| 1205 | if (this->status == STATUS_PRE_ACTIVE) { |
| 1206 | /* The client is not yet caught up? */ |
| 1207 | if (frame + Ticks::DAY_TICKS < _frame_counter) return NETWORK_RECV_STATUS_OKAY; |
| 1208 | |
| 1209 | /* Now it is! Unpause the game */ |
| 1210 | Debug(net, 9, "client[{}] status = ACTIVE", this->client_id); |
| 1211 | this->status = STATUS_ACTIVE; |
| 1212 | this->last_token_frame = _frame_counter; |
| 1213 | |
| 1214 | /* Execute script for, e.g. MOTD */ |
| 1215 | IConsoleCmdExec("exec scripts/on_server_connect.scr 0"); |
| 1216 | } |
| 1217 | |
| 1218 | /* Get, and validate the token. */ |
| 1219 | uint8_t token = p.Recv_uint8(); |
| 1220 | if (token == this->last_token) { |
| 1221 | /* We differentiate between last_token_frame and last_frame so the lag |
| 1222 | * test uses the actual lag of the client instead of the lag for getting |
| 1223 | * the token back and forth; after all, the token is only sent every |
| 1224 | * time we receive a PACKET_CLIENT_ACK, after which we will send a new |
| 1225 | * token to the client. If the lag would be one day, then we would not |
| 1226 | * be sending the new token soon enough for the new daily scheduled |
| 1227 | * PACKET_CLIENT_ACK. This would then register the lag of the client as |
| 1228 | * two days, even when it's only a single day. */ |
| 1229 | this->last_token_frame = _frame_counter; |
| 1230 | /* Request a new token. */ |
| 1231 | this->last_token = 0; |
| 1232 | } |
| 1233 | |
| 1234 | /* The client received the frame, make note of it */ |
| 1235 | this->last_frame = frame; |
| 1236 | /* With those 2 values we can calculate the lag realtime */ |
| 1237 | this->last_frame_server = _frame_counter; |
| 1238 | return NETWORK_RECV_STATUS_OKAY; |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | /** |
nothing calls this directly
no test coverage detected