Skip to content

Commit

Permalink
Client net protocol version updated; server now handles protocol vers…
Browse files Browse the repository at this point in the history
…ions differently; multiplayer world activity cycles fixed
  • Loading branch information
Aidoneus committed Mar 27, 2023
1 parent bc11352 commit 1272766
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
39 changes: 30 additions & 9 deletions server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#define LAG -3000
//#define EVENTS_LOG
#define SERVER_VERSION 1
#define MIN_SERVER_VERSION 1
#define MAX_SERVER_VERSION 2

#ifdef EVENTS_LOG
XStream fout("lst", XS_OUT);
Expand Down Expand Up @@ -957,7 +958,13 @@ void Player::identification() {
if (len > strlen(request_str) + 1)
client_version = ((unsigned char *)string)[len - 1];
strcpy(string, response_str);
string[strlen(string) + 1] = SERVER_VERSION;
if (client_version < MIN_SERVER_VERSION || client_version > MAX_SERVER_VERSION) {
// Client is not supported, so indicate the real latest supported protocol version
string[strlen(string) + 1] = MAX_SERVER_VERSION;
} else {
// Client's protocol is within supported range, so send them identical version to prevent crashes
string[strlen(string) + 1] = client_version;
}
socket.send(string, strlen(string) + 2);
return;
}
Expand Down Expand Up @@ -1190,7 +1197,7 @@ int Player::receive() {
IN_EVENTS_LOG(GAMES_LIST_QUERY);
break;

case ATTACH_TO_GAME:
case ATTACH_TO_GAME: {
if (game || ID)
SERVER_ERROR_NO_EXIT("Player have already been attached to game", game->ID);
if ((game = server->games.search(in_buffer.get_int())) == 0 ||
Expand All @@ -1207,7 +1214,16 @@ int Player::receive() {
out_buffer.end_event();

IN_EVENTS_LOG(ATTACH_TO_GAME);
break;

if (this->client_version > 1) {
long int t = 0;
time(&t);
out_buffer.begin_event(zTIME_RESPONSE);
out_buffer < (unsigned int)t;
out_buffer.end_event();
OUT_EVENTS_LOG(zTIME_RESPONSE);
}
} break;

case RESTORE_CONNECTION: {
Player *p;
Expand Down Expand Up @@ -1299,6 +1315,7 @@ int Player::receive() {
out_buffer.begin_event(SERVER_TIME);
out_buffer < (unsigned int)GLOBAL_CLOCK();
out_buffer.end_event();

IN_EVENTS_LOG(SERVER_TIME_QUERY);
OUT_EVENTS_LOG(SERVER_TIME);
break;
Expand All @@ -1312,7 +1329,7 @@ int Player::receive() {
if (size != sizeof(ServerData))
SERVER_ERROR_NO_EXIT("Incorrect Server Data", size);
in_buffer.read((unsigned char *)&game->data, sizeof(ServerData));
game->client_version = client_version;
game->client_version = MIN_SERVER_VERSION;
IN_EVENTS_LOG(SET_GAME_DATA);
} break;

Expand Down Expand Up @@ -1895,17 +1912,21 @@ void Server::get_games_list(OutputEventBuffer &out_buffer, int client_version) {
int num = 0;
Game *g = games.first();
while (g) {
if (g->data.GameType != UNCONFIGURED && g->used_players_IDs != 0x7fffffff &&
g->client_version == client_version)
if (g->data.GameType != UNCONFIGURED && g->used_players_IDs != 0x7fffffff)
// This check isn't needed for now, as both clients' and games' versions are guaranteed to be within supported
// range; though later this condition might end up being needed in some adjusted form in case of further updates
//g->client_version == client_version)
num++;
g = g->next;
}
out_buffer.begin_event(GAMES_LIST_RESPONSE);
out_buffer < (unsigned char)num;
g = games.first();
while (g) {
if (g->data.GameType != UNCONFIGURED && g->used_players_IDs != 0x7fffffff &&
g->client_version == client_version) {
if (g->data.GameType != UNCONFIGURED && g->used_players_IDs != 0x7fffffff) {
// This check isn't needed for now, as both clients' and games' versions are guaranteed to be within supported
// range; though later this condition might end up being needed in some adjusted form in case of further updates
//g->client_version == client_version) {
out_buffer < g->ID < g->name < ": " <= g->players.size() < " " <
(g->data.GameType == VAN_WAR ? "V" : (g->data.GameType == MECHOSOMA ? "M" : "P"));

Expand Down
12 changes: 5 additions & 7 deletions src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extern XStream fout;
extern int frame;
extern int GlobalExit;

#define CLIENT_VERSION 1
#define SERVER_VERSION 1
#define CLIENT_VERSION 2
#define SERVER_VERSION 2

//zmod
int zserver_version = 0;
Expand Down Expand Up @@ -273,7 +273,6 @@ int identification(XSocket& socket)
// return 0;
}
}

// /zMod ---------------------------------------------------------

return 1;
Expand Down Expand Up @@ -812,10 +811,9 @@ int connect_to_server(ServerFindChain* p)
events_in.ignore_event();

zGameBirthTime = 0;
if (zserver_version > 1) {
//std::cout<<"zTIME_RESPONSE"<<std::endl;
events_in.receive_waiting_for_event(zTIME_RESPONSE); //ZMOD second network packet
//std::cout<<"[ok]"<<std::endl;
if (zserver_version > 1 || SERVER_VERSION > 1) {
// zMod second network packet, used as a seed for world activity cycles
events_in.receive_waiting_for_event(zTIME_RESPONSE);
zGameBirthTime = events_in.get_int();
events_in.ignore_event();
}
Expand Down

0 comments on commit 1272766

Please sign in to comment.