1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 03:53:07 +01:00

Start adding network code

This commit is contained in:
duncanspumpkin
2017-03-21 19:05:53 +00:00
committed by Michał Janiszewski
parent c483c319fc
commit e7c66bb208
5 changed files with 46 additions and 0 deletions

View File

@@ -115,6 +115,16 @@ namespace GameActions
GameActionResult result = Query(action);
if (result.Error == GA_ERROR::OK)
{
// Networked games send actions to the server to be run
if (network_get_mode() != NETWORK_MODE_NONE)
{
// Action has come from server.
if (!(actionFlags & GA_FLAGS::CLIENT_ONLY) && !(actionFlags & GA_FLAGS::GHOST))
{
network_send_game_action(action);
}
}
// Execute the action, changing the game state
result = action->Execute();

View File

@@ -48,6 +48,7 @@ namespace GA_FLAGS
{
constexpr uint16 ALLOW_WHILE_PAUSED = 1 << 0;
constexpr uint16 CLIENT_ONLY = 1 << 1;
constexpr uint16 GHOST = 1 << 2;
}
/**

View File

@@ -40,6 +40,7 @@ sint32 _pickup_peep_old_x = SPRITE_LOCATION_NULL;
#include <set>
#include <string>
#include "../actions/GameAction.h"
#include "../core/Console.hpp"
#include "../core/FileStream.hpp"
#include "../core/Json.hpp"
@@ -1113,6 +1114,22 @@ void Network::Server_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx
SendPacketToClients(*packet, false, true);
}
void Network::Client_Send_GAME_ACTION(const IGameAction * action)
{
std::unique_ptr<NetworkPacket> packet(NetworkPacket::Allocate());
*packet << (uint32)NETWORK_COMMAND_GAME_ACTION << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED)
<< ecx << edx << esi << edi << ebp << callback;
server_connection.QueuePacket(std::move(packet));
}
void Network::Server_Send_GAME_ACTION(const IGameAction * action)
{
std::unique_ptr<NetworkPacket> packet(NetworkPacket::Allocate());
*packet << (uint32)NETWORK_COMMAND_GAME_ACTION << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED)
<< ecx << edx << esi << edi << ebp << playerid << callback;
SendPacketToClients(*packet);
}
void Network::Server_Send_TICK()
{
last_tick_sent_time = platform_get_ticks();
@@ -2866,6 +2883,18 @@ void network_send_chat(const char* text)
}
}
void network_send_game_action(const IGameAction * action)
{
switch (gNetwork.GetMode()) {
case NETWORK_MODE_SERVER:
gNetwork.Server_Send_GAME_ACTION(action);
break;
case NETWORK_MODE_CLIENT:
gNetwork.Client_Send_GAME_ACTION(action);
break;
}
}
void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback)
{
switch (gNetwork.GetMode()) {

View File

@@ -50,6 +50,7 @@ enum NETWORK_COMMAND
NETWORK_COMMAND_EVENT,
NETWORK_COMMAND_TOKEN,
NETWORK_COMMAND_OBJECTS,
NETWORK_COMMAND_GAME_ACTION,
NETWORK_COMMAND_MAX,
NETWORK_COMMAND_INVALID = -1
};

View File

@@ -141,6 +141,8 @@ public:
void Server_Send_CHAT(const char* text);
void Client_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback);
void Server_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 playerid, uint8 callback);
void Client_Send_GAME_ACTION(const IGameAction * action);
void Server_Send_GAME_ACTION(const IGameAction * action);
void Server_Send_TICK();
void Server_Send_PLAYERLIST();
void Client_Send_PING();
@@ -320,6 +322,9 @@ sint32 network_get_pickup_peep_old_x(uint8 playerid);
void network_send_map();
void network_send_chat(const char* text);
void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback);
#ifdef __cplusplus
void network_send_game_action(const IGameAction * action);
#endif
void network_send_password(const char* password);
void network_set_password(const char* password);