mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
add last player action to player list
This commit is contained in:
@@ -4000,6 +4000,8 @@ STR_5658 :Park Funding
|
||||
STR_5659 :Kick Player
|
||||
STR_5660 :Modify Groups
|
||||
STR_5661 :Set Player Group
|
||||
STR_5662 :N/A
|
||||
STR_5704 :Last Action:
|
||||
STR_5705 :Can't set to this group
|
||||
STR_5706 :Can't remove group that players belong to
|
||||
STR_5707 :This group cannot be modified
|
||||
|
||||
@@ -543,6 +543,7 @@ int game_do_command_p(int command, int *eax, int *ebx, int *ecx, int *edx, int *
|
||||
}
|
||||
|
||||
if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST)) {
|
||||
network_set_player_last_action(network_get_player_index(network_get_current_player_id()), command);
|
||||
network_add_player_money_spent(network_get_current_player_id(), cost);
|
||||
}
|
||||
|
||||
|
||||
@@ -2288,7 +2288,9 @@ enum {
|
||||
STR_ACTION_KICK_PLAYER = 5659,
|
||||
STR_ACTION_MODIFY_GROUPS = 5660,
|
||||
STR_ACTION_SET_PLAYER_GROUP = 5661,
|
||||
STR_ACTION_NA = 5662,
|
||||
|
||||
STR_LAST_ACTION = 5704,
|
||||
STR_CANT_SET_TO_THIS_GROUP = 5705,
|
||||
STR_CANT_REMOVE_GROUP_THAT_PLAYERS_BELONG_TO = 5706,
|
||||
STR_THIS_GROUP_CANNOT_BE_MODIFIED = 5707,
|
||||
|
||||
@@ -190,20 +190,20 @@ NetworkPlayer::NetworkPlayer()
|
||||
money_spent = MONEY(0, 0);
|
||||
commands_ran = 0;
|
||||
group = 0;
|
||||
reserved = 0;
|
||||
last_action = -999;
|
||||
}
|
||||
|
||||
void NetworkPlayer::Read(NetworkPacket& packet)
|
||||
{
|
||||
const char* name = packet.ReadString();
|
||||
SetName(name);
|
||||
packet >> id >> flags >> group >> reserved;
|
||||
packet >> id >> flags >> group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::Write(NetworkPacket& packet)
|
||||
{
|
||||
packet.WriteString((const char*)name);
|
||||
packet << id << flags << group << reserved;
|
||||
packet << id << flags << group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::SetName(const char* name)
|
||||
@@ -1436,6 +1436,8 @@ void Network::ProcessGameCommandQueue()
|
||||
if (cost != MONEY32_UNDEFINED) {
|
||||
NetworkPlayer* player = GetPlayerByID(gc.playerid);
|
||||
if (player) {
|
||||
player->last_action = gNetworkActions.FindCommand(gc.esi);
|
||||
player->last_action_time = SDL_GetTicks();
|
||||
player->AddMoneySpent(cost);
|
||||
}
|
||||
}
|
||||
@@ -1712,6 +1714,9 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
|
||||
if (cost == MONEY32_UNDEFINED) {
|
||||
return;
|
||||
}
|
||||
|
||||
connection.player->last_action = gNetworkActions.FindCommand(commandCommand);
|
||||
connection.player->last_action_time = SDL_GetTicks();
|
||||
connection.player->AddMoneySpent(cost);
|
||||
Server_Send_GAMECMD(args[0], args[1], args[2], args[3], args[4], args[5], args[6], playerid, callback);
|
||||
}
|
||||
@@ -1914,6 +1919,20 @@ void network_add_player_money_spent(unsigned int index, money32 cost)
|
||||
gNetwork.player_list[index]->AddMoneySpent(cost);
|
||||
}
|
||||
|
||||
int network_get_player_last_action(unsigned int index)
|
||||
{
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), gNetwork.player_list[index]->last_action_time + 2000)) {
|
||||
return -999;
|
||||
}
|
||||
return gNetwork.player_list[index]->last_action;
|
||||
}
|
||||
|
||||
void network_set_player_last_action(unsigned int index, int command)
|
||||
{
|
||||
gNetwork.player_list[index]->last_action = gNetworkActions.FindCommand(command);
|
||||
gNetwork.player_list[index]->last_action_time = SDL_GetTicks();
|
||||
}
|
||||
|
||||
unsigned int network_get_player_commands_ran(unsigned int index)
|
||||
{
|
||||
return gNetwork.player_list[index]->commands_ran;
|
||||
@@ -2207,8 +2226,10 @@ int network_get_player_ping(unsigned int index) { return 0; }
|
||||
int network_get_player_id(unsigned int index) { return 0; }
|
||||
money32 network_get_player_money_spent(unsigned int index) { return MONEY(0, 0); }
|
||||
void network_add_player_money_spent(unsigned int index, money32 cost) { }
|
||||
int network_get_player_last_action(unsigned int index) { return -999; }
|
||||
void network_set_player_last_action(unsigned int index, int command) { }
|
||||
unsigned int network_get_player_commands_ran(unsigned int index) { return 0; }
|
||||
int network_get_player_index(uint8 id) { return -1; };
|
||||
int network_get_player_index(uint8 id) { return -1; }
|
||||
uint8 network_get_player_group(unsigned int index) { return 0; }
|
||||
void network_set_player_group(unsigned int index, unsigned int groupindex) { }
|
||||
int network_get_group_index(uint8 id) { return -1; }
|
||||
|
||||
@@ -157,9 +157,10 @@ public:
|
||||
uint16 ping;
|
||||
uint8 flags;
|
||||
uint8 group;
|
||||
uint16 reserved;
|
||||
money32 money_spent;
|
||||
unsigned int commands_ran;
|
||||
int last_action;
|
||||
uint32 last_action_time;
|
||||
};
|
||||
|
||||
class NetworkAction
|
||||
@@ -208,7 +209,7 @@ public:
|
||||
std::string& GetName();
|
||||
void SetName(std::string name);
|
||||
rct_string_id GetNameStringId();
|
||||
std::array<uint8, 16> actions_allowed;
|
||||
std::array<uint8, 8> actions_allowed;
|
||||
uint8 id;
|
||||
|
||||
private:
|
||||
@@ -420,6 +421,8 @@ int network_get_player_ping(unsigned int index);
|
||||
int network_get_player_id(unsigned int index);
|
||||
money32 network_get_player_money_spent(unsigned int index);
|
||||
void network_add_player_money_spent(unsigned int index, money32 cost);
|
||||
int network_get_player_last_action(unsigned int index);
|
||||
void network_set_player_last_action(unsigned int index, int command);
|
||||
unsigned int network_get_player_commands_ran(unsigned int index);
|
||||
int network_get_player_index(uint8 id);
|
||||
uint8 network_get_player_group(unsigned int index);
|
||||
|
||||
@@ -288,7 +288,7 @@ static void window_multiplayer_players_mouseup(rct_window *w, int widgetIndex)
|
||||
|
||||
static void window_multiplayer_players_resize(rct_window *w)
|
||||
{
|
||||
window_set_resize(w, 320, 124, 500, 450);
|
||||
window_set_resize(w, 420, 124, 500, 450);
|
||||
|
||||
w->no_list_items = network_get_num_players();
|
||||
w->list_item_positions[0] = 0;
|
||||
@@ -384,7 +384,8 @@ static void window_multiplayer_players_paint(rct_window *w, rct_drawpixelinfo *d
|
||||
// Columns
|
||||
gfx_draw_string_left(dpi, STR_PLAYER, NULL, w->colours[2], w->x + 6, 58 - 12 + w->y + 1);
|
||||
gfx_draw_string_left(dpi, STR_GROUP, NULL, w->colours[2], w->x + 180, 58 - 12 + w->y + 1);
|
||||
gfx_draw_string_left(dpi, STR_PING, NULL, w->colours[2], w->x + 263, 58 - 12 + w->y + 1);
|
||||
gfx_draw_string_left(dpi, STR_LAST_ACTION, NULL, w->colours[2], w->x + 263, 58 - 12 + w->y + 1);
|
||||
gfx_draw_string_left(dpi, STR_PING, NULL, w->colours[2], w->x + 363, 58 - 12 + w->y + 1);
|
||||
|
||||
// Number of players
|
||||
stringId = w->no_list_items == 1 ? STR_X_PLAYER : STR_X_PLAYERS;
|
||||
@@ -434,6 +435,14 @@ static void window_multiplayer_players_scrollpaint(rct_window *w, rct_drawpixeli
|
||||
gfx_draw_string(dpi, buffer, colour, 173, y - 1);
|
||||
}
|
||||
|
||||
// Draw last action
|
||||
int action = network_get_player_last_action(i);
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = STR_ACTION_NA;
|
||||
if (action != -999) {
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = network_get_action_name_string_id(action);
|
||||
}
|
||||
gfx_draw_string_left(dpi, 1191, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, 256, y - 1);
|
||||
|
||||
// Draw ping
|
||||
lineCh = buffer;
|
||||
int ping = network_get_player_ping(i);
|
||||
@@ -446,7 +455,7 @@ static void window_multiplayer_players_scrollpaint(rct_window *w, rct_drawpixeli
|
||||
lineCh = utf8_write_codepoint(lineCh, FORMAT_RED);
|
||||
}
|
||||
sprintf(lineCh, "%d ms", ping);
|
||||
gfx_draw_string(dpi, buffer, colour, 256, y - 1);
|
||||
gfx_draw_string(dpi, buffer, colour, 356, y - 1);
|
||||
}
|
||||
y += 10;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user