forked from EXTERNAL/bareiron
explicitly handle running out of player slots
This commit is contained in:
@@ -131,6 +131,7 @@ extern BlockChange block_changes[20000];
|
|||||||
extern int block_changes_count;
|
extern int block_changes_count;
|
||||||
|
|
||||||
extern PlayerData player_data[MAX_PLAYERS];
|
extern PlayerData player_data[MAX_PLAYERS];
|
||||||
|
extern int player_data_count;
|
||||||
|
|
||||||
extern MobData mob_data[MAX_MOBS];
|
extern MobData mob_data[MAX_MOBS];
|
||||||
|
|
||||||
|
@@ -40,5 +40,6 @@ BlockChange block_changes[20000];
|
|||||||
int block_changes_count = 0;
|
int block_changes_count = 0;
|
||||||
|
|
||||||
PlayerData player_data[MAX_PLAYERS];
|
PlayerData player_data[MAX_PLAYERS];
|
||||||
|
int player_data_count = 0;
|
||||||
|
|
||||||
MobData mob_data[MAX_MOBS];
|
MobData mob_data[MAX_MOBS];
|
||||||
|
@@ -47,7 +47,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
|
|||||||
uint8_t uuid[16];
|
uint8_t uuid[16];
|
||||||
char name[16];
|
char name[16];
|
||||||
if (cs_loginStart(client_fd, uuid, name)) break;
|
if (cs_loginStart(client_fd, uuid, name)) break;
|
||||||
if (reservePlayerData(client_fd, uuid, name)) break;
|
if (reservePlayerData(client_fd, uuid, name)) {
|
||||||
|
recv_count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (sc_loginSuccess(client_fd, uuid, name)) break;
|
if (sc_loginSuccess(client_fd, uuid, name)) break;
|
||||||
} else if (state == STATE_CONFIGURATION) {
|
} else if (state == STATE_CONFIGURATION) {
|
||||||
if (cs_clientInformation(client_fd)) break;
|
if (cs_clientInformation(client_fd)) break;
|
||||||
|
@@ -79,10 +79,12 @@ int reservePlayerData (int client_fd, uint8_t *uuid, char *name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty) {
|
if (empty) {
|
||||||
|
if (player_data_count >= MAX_PLAYERS) return 1;
|
||||||
player_data[i].client_fd = client_fd;
|
player_data[i].client_fd = client_fd;
|
||||||
memcpy(player_data[i].uuid, uuid, 16);
|
memcpy(player_data[i].uuid, uuid, 16);
|
||||||
memcpy(player_data[i].name, name, 16);
|
memcpy(player_data[i].name, name, 16);
|
||||||
resetPlayerData(&player_data[i]);
|
resetPlayerData(&player_data[i]);
|
||||||
|
player_data_count ++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +107,12 @@ void clearPlayerFD (int client_fd) {
|
|||||||
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
for (int i = 0; i < MAX_PLAYERS; i ++) {
|
||||||
if (player_data[i].client_fd == client_fd) {
|
if (player_data[i].client_fd == client_fd) {
|
||||||
player_data[i].client_fd = -1;
|
player_data[i].client_fd = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < MAX_PLAYERS * 2; i += 2) {
|
||||||
|
if (client_states[i] == client_fd) {
|
||||||
|
client_states[i] = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user