Format to break long lines in network.cpp

[ci skip]
This commit is contained in:
Michał Janiszewski 2016-05-21 17:12:40 +02:00
parent bf24f5eef8
commit 8066ed6ecc
2 changed files with 86 additions and 32 deletions

View file

@ -398,7 +398,8 @@ int NetworkConnection::ReadPacket()
} else {
// read packet data
if (inboundpacket.data->capacity() > 0) {
int readBytes = recv(socket, (char*)&inboundpacket.GetData()[inboundpacket.transferred - sizeof(inboundpacket.size)], sizeof(inboundpacket.size) + inboundpacket.size - inboundpacket.transferred, 0);
int readBytes = recv(socket, (char*)&inboundpacket.GetData()[inboundpacket.transferred - sizeof(inboundpacket.size)],
sizeof(inboundpacket.size) + inboundpacket.size - inboundpacket.transferred, 0);
if (readBytes == SOCKET_ERROR || readBytes == 0) {
if (LAST_SOCKET_ERROR() != EWOULDBLOCK && LAST_SOCKET_ERROR() != EAGAIN) {
return NETWORK_READPACKET_DISCONNECTED;
@ -880,7 +881,8 @@ void Network::UpdateClient()
break;
}
if (connect(server_connection.socket, (sockaddr *)&(*server_address.ss), (*server_address.ss_len)) == SOCKET_ERROR && (LAST_SOCKET_ERROR() == EINPROGRESS || LAST_SOCKET_ERROR() == EWOULDBLOCK)){
if (connect(server_connection.socket, (sockaddr *)&(*server_address.ss),
(*server_address.ss_len)) == SOCKET_ERROR && (LAST_SOCKET_ERROR() == EINPROGRESS || LAST_SOCKET_ERROR() == EWOULDBLOCK)){
char str_connecting[256];
format_string(str_connecting, STR_MULTIPLAYER_CONNECTING, NULL);
window_network_status_open(str_connecting, []() -> void {
@ -946,7 +948,8 @@ void Network::UpdateClient()
}break;
case NETWORK_STATUS_CONNECTED:
if (!ProcessConnection(server_connection)) {
if (server_connection.authstatus == NETWORK_AUTH_REQUIREPASSWORD) { // Do not show disconnect message window when password window closed/canceled
// Do not show disconnect message window when password window closed/canceled
if (server_connection.authstatus == NETWORK_AUTH_REQUIREPASSWORD) {
window_network_status_close();
} else {
char str_disconnected[256];
@ -1219,7 +1222,9 @@ NetworkGroup* Network::AddGroup()
int newid = -1;
// Find first unused group id
for (int id = 0; id < 255; id++) {
if (std::find_if(group_list.begin(), group_list.end(), [&id](std::unique_ptr<NetworkGroup> const& group) { return group->id == id; }) == group_list.end()) {
if (std::find_if(group_list.begin(), group_list.end(), [&id](std::unique_ptr<NetworkGroup> const& group) {
return group->id == id;
}) == group_list.end()) {
newid = id;
break;
}
@ -1439,14 +1444,16 @@ void Network::Server_Send_CHAT(const char* text)
void Network::Client_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback)
{
std::unique_ptr<NetworkPacket> packet = std::move(NetworkPacket::Allocate());
*packet << (uint32)NETWORK_COMMAND_GAMECMD << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED) << ecx << edx << esi << edi << ebp << callback;
*packet << (uint32)NETWORK_COMMAND_GAMECMD << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED)
<< ecx << edx << esi << edi << ebp << callback;
server_connection.QueuePacket(std::move(packet));
}
void Network::Server_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 playerid, uint8 callback)
{
std::unique_ptr<NetworkPacket> packet = std::move(NetworkPacket::Allocate());
*packet << (uint32)NETWORK_COMMAND_GAMECMD << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED) << ecx << edx << esi << edi << ebp << playerid << callback;
*packet << (uint32)NETWORK_COMMAND_GAMECMD << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED)
<< ecx << edx << esi << edi << ebp << playerid << callback;
SendPacketToClients(*packet);
}
@ -1674,7 +1681,9 @@ void Network::RemoveClient(std::unique_ptr<NetworkConnection>& connection)
chat_history_add(text);
gNetwork.Server_Send_EVENT_PLAYER_DISCONNECTED((char*)connection_player->name, connection->getLastDisconnectReason());
}
player_list.erase(std::remove_if(player_list.begin(), player_list.end(), [connection_player](std::unique_ptr<NetworkPlayer>& player){ return player.get() == connection_player; }), player_list.end());
player_list.erase(std::remove_if(player_list.begin(), player_list.end(), [connection_player](std::unique_ptr<NetworkPlayer>& player){
return player.get() == connection_player;
}), player_list.end());
client_connection_list.remove(connection);
Server_Send_PLAYERLIST();
}
@ -1686,7 +1695,9 @@ NetworkPlayer* Network::AddPlayer()
if (GetMode() == NETWORK_MODE_SERVER) {
// Find first unused player id
for (int id = 0; id < 255; id++) {
if (std::find_if(player_list.begin(), player_list.end(), [&id](std::unique_ptr<NetworkPlayer> const& player) { return player->id == id; }) == player_list.end()) {
if (std::find_if(player_list.begin(), player_list.end(), [&id](std::unique_ptr<NetworkPlayer> const& player) {
return player->id == id;
}) == player_list.end()) {
newid = id;
break;
}
@ -1708,7 +1719,8 @@ void Network::PrintError()
{
#ifdef __WINDOWS__
wchar_t *s = NULL;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, LAST_SOCKET_ERROR(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&s, 0, NULL);
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
LAST_SOCKET_ERROR(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&s, 0, NULL);
fprintf(stderr, "%S\n", s);
LocalFree(s);
#else

View file

@ -133,11 +133,17 @@ public:
uint8* GetData();
uint32 GetCommand();
template <typename T>
NetworkPacket& operator<<(T value) { T swapped = ByteSwapBE(value); uint8* bytes = (uint8*)&swapped; data->insert(data->end(), bytes, bytes + sizeof(value)); return *this; }
NetworkPacket& operator<<(T value) {
T swapped = ByteSwapBE(value); uint8* bytes = (uint8*)&swapped; data->insert(data->end(), bytes, bytes + sizeof(value));
return *this;
}
void Write(uint8* bytes, unsigned int size);
void WriteString(const char* string);
template <typename T>
NetworkPacket& operator>>(T& value) { if (read + sizeof(value) > size) { value = 0; } else { value = ByteSwapBE(*((T*)&GetData()[read])); read += sizeof(value); } return *this; }
NetworkPacket& operator>>(T& value) {
if (read + sizeof(value) > size) { value = 0; } else { value = ByteSwapBE(*((T*)&GetData()[read])); read += sizeof(value); }
return *this;
}
const uint8* Read(unsigned int size);
const char* ReadString();
void Clear();
@ -183,26 +189,59 @@ public:
int FindCommand(int command);
int FindCommandByPermissionName(const std::string &permission_name);
const std::vector<NetworkAction> actions = {
{STR_ACTION_CHAT, "PERMISSION_CHAT", {-1}},
{STR_ACTION_TERRAFORM, "PERMISSION_TERRAFORM", {GAME_COMMAND_SET_LAND_HEIGHT, GAME_COMMAND_RAISE_LAND, GAME_COMMAND_LOWER_LAND, GAME_COMMAND_EDIT_LAND_SMOOTH, GAME_COMMAND_CHANGE_SURFACE_STYLE}},
{STR_ACTION_SET_WATER_LEVEL, "PERMISSION_SET_WATER_LEVEL", {GAME_COMMAND_SET_WATER_HEIGHT, GAME_COMMAND_RAISE_WATER, GAME_COMMAND_LOWER_WATER}},
{STR_ACTION_TOGGLE_PAUSE, "PERMISSION_TOGGLE_PAUSE", {GAME_COMMAND_TOGGLE_PAUSE}},
{STR_ACTION_CREATE_RIDE, "PERMISSION_CREATE_RIDE", {GAME_COMMAND_CREATE_RIDE}},
{STR_ACTION_REMOVE_RIDE, "PERMISSION_REMOVE_RIDE", {GAME_COMMAND_DEMOLISH_RIDE}},
{STR_ACTION_BUILD_RIDE, "PERMISSION_BUILD_RIDE", {GAME_COMMAND_PLACE_TRACK, GAME_COMMAND_REMOVE_TRACK, GAME_COMMAND_SET_MAZE_TRACK, GAME_COMMAND_PLACE_TRACK_DESIGN, GAME_COMMAND_PLACE_MAZE_DESIGN, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT}},
{STR_ACTION_RIDE_PROPERTIES, "PERMISSION_RIDE_PROPERTIES", {GAME_COMMAND_SET_RIDE_NAME, GAME_COMMAND_SET_RIDE_APPEARANCE, GAME_COMMAND_SET_RIDE_STATUS, GAME_COMMAND_SET_RIDE_VEHICLES, GAME_COMMAND_SET_RIDE_SETTING, GAME_COMMAND_SET_RIDE_PRICE, GAME_COMMAND_SET_BRAKES_SPEED}},
{STR_ACTION_SCENERY, "PERMISSION_SCENERY", {GAME_COMMAND_REMOVE_SCENERY, GAME_COMMAND_PLACE_SCENERY, GAME_COMMAND_SET_BRAKES_SPEED, GAME_COMMAND_REMOVE_FENCE, GAME_COMMAND_PLACE_FENCE, GAME_COMMAND_REMOVE_LARGE_SCENERY, GAME_COMMAND_PLACE_LARGE_SCENERY, GAME_COMMAND_PLACE_BANNER, GAME_COMMAND_REMOVE_BANNER, GAME_COMMAND_SET_SCENERY_COLOUR, GAME_COMMAND_SET_FENCE_COLOUR, GAME_COMMAND_SET_LARGE_SCENERY_COLOUR, GAME_COMMAND_SET_BANNER_COLOUR, GAME_COMMAND_SET_BANNER_NAME, GAME_COMMAND_SET_SIGN_NAME, GAME_COMMAND_SET_BANNER_STYLE, GAME_COMMAND_SET_SIGN_STYLE}},
{STR_ACTION_PATH, "PERMISSION_PATH", {GAME_COMMAND_PLACE_PATH, GAME_COMMAND_PLACE_PATH_FROM_TRACK, GAME_COMMAND_REMOVE_PATH}},
{STR_ACTION_CLEAR_LANDSCAPE, "PERMISSION_CLEAR_LANDSCAPE", {GAME_COMMAND_CLEAR_SCENERY}},
{STR_ACTION_GUEST, "PERMISSION_GUEST", {GAME_COMMAND_SET_GUEST_NAME}},
{STR_ACTION_STAFF, "PERMISSION_STAFF", {GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, GAME_COMMAND_SET_STAFF_PATROL, GAME_COMMAND_FIRE_STAFF_MEMBER, GAME_COMMAND_SET_STAFF_ORDER, GAME_COMMAND_SET_STAFF_COLOUR, GAME_COMMAND_SET_STAFF_NAME}},
{STR_ACTION_PARK_PROPERTIES, "PERMISSION_PARK_PROPERTIES", {GAME_COMMAND_SET_PARK_NAME, GAME_COMMAND_SET_PARK_OPEN, GAME_COMMAND_SET_PARK_ENTRANCE_FEE, GAME_COMMAND_SET_LAND_OWNERSHIP, GAME_COMMAND_BUY_LAND_RIGHTS, GAME_COMMAND_PLACE_PARK_ENTRANCE, GAME_COMMAND_REMOVE_PARK_ENTRANCE}},
{STR_ACTION_PARK_FUNDING, "PERMISSION_PARK_FUNDING", {GAME_COMMAND_SET_CURRENT_LOAN, GAME_COMMAND_SET_RESEARCH_FUNDING, GAME_COMMAND_START_MARKETING_CAMPAIGN}},
{STR_ACTION_KICK_PLAYER, "PERMISSION_KICK_PLAYER", {GAME_COMMAND_KICK_PLAYER}},
{STR_ACTION_MODIFY_GROUPS, "PERMISSION_MODIFY_GROUPS", {GAME_COMMAND_MODIFY_GROUPS}},
{STR_ACTION_SET_PLAYER_GROUP, "PERMISSION_SET_PLAYER_GROUP", {GAME_COMMAND_SET_PLAYER_GROUP}},
{STR_ACTION_CHEAT, "PERMISSION_CHEAT", {GAME_COMMAND_CHEAT}},
{STR_ACTION_TOGGLE_SCENERY_CLUSTER, "PERMISSION_TOGGLE_SCENERY_CLUSTER", {-2}}
{STR_ACTION_CHAT, "PERMISSION_CHAT",
{-1}},
{STR_ACTION_TERRAFORM, "PERMISSION_TERRAFORM",
{GAME_COMMAND_SET_LAND_HEIGHT, GAME_COMMAND_RAISE_LAND, GAME_COMMAND_LOWER_LAND,
GAME_COMMAND_EDIT_LAND_SMOOTH, GAME_COMMAND_CHANGE_SURFACE_STYLE}},
{STR_ACTION_SET_WATER_LEVEL, "PERMISSION_SET_WATER_LEVEL",
{GAME_COMMAND_SET_WATER_HEIGHT, GAME_COMMAND_RAISE_WATER, GAME_COMMAND_LOWER_WATER}},
{STR_ACTION_TOGGLE_PAUSE, "PERMISSION_TOGGLE_PAUSE",
{GAME_COMMAND_TOGGLE_PAUSE}},
{STR_ACTION_CREATE_RIDE, "PERMISSION_CREATE_RIDE",
{GAME_COMMAND_CREATE_RIDE}},
{STR_ACTION_REMOVE_RIDE, "PERMISSION_REMOVE_RIDE",
{GAME_COMMAND_DEMOLISH_RIDE}},
{STR_ACTION_BUILD_RIDE, "PERMISSION_BUILD_RIDE",
{GAME_COMMAND_PLACE_TRACK, GAME_COMMAND_REMOVE_TRACK, GAME_COMMAND_SET_MAZE_TRACK,
GAME_COMMAND_PLACE_TRACK_DESIGN, GAME_COMMAND_PLACE_MAZE_DESIGN, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT}},
{STR_ACTION_RIDE_PROPERTIES, "PERMISSION_RIDE_PROPERTIES",
{GAME_COMMAND_SET_RIDE_NAME, GAME_COMMAND_SET_RIDE_APPEARANCE, GAME_COMMAND_SET_RIDE_STATUS,
GAME_COMMAND_SET_RIDE_VEHICLES, GAME_COMMAND_SET_RIDE_SETTING, GAME_COMMAND_SET_RIDE_PRICE,
GAME_COMMAND_SET_BRAKES_SPEED}},
{STR_ACTION_SCENERY, "PERMISSION_SCENERY",
{GAME_COMMAND_REMOVE_SCENERY, GAME_COMMAND_PLACE_SCENERY, GAME_COMMAND_SET_BRAKES_SPEED,
GAME_COMMAND_REMOVE_FENCE, GAME_COMMAND_PLACE_FENCE, GAME_COMMAND_REMOVE_LARGE_SCENERY,
GAME_COMMAND_PLACE_LARGE_SCENERY, GAME_COMMAND_PLACE_BANNER, GAME_COMMAND_REMOVE_BANNER,
GAME_COMMAND_SET_SCENERY_COLOUR, GAME_COMMAND_SET_FENCE_COLOUR, GAME_COMMAND_SET_LARGE_SCENERY_COLOUR,
GAME_COMMAND_SET_BANNER_COLOUR, GAME_COMMAND_SET_BANNER_NAME, GAME_COMMAND_SET_SIGN_NAME,
GAME_COMMAND_SET_BANNER_STYLE, GAME_COMMAND_SET_SIGN_STYLE}},
{STR_ACTION_PATH, "PERMISSION_PATH",
{GAME_COMMAND_PLACE_PATH, GAME_COMMAND_PLACE_PATH_FROM_TRACK, GAME_COMMAND_REMOVE_PATH}},
{STR_ACTION_CLEAR_LANDSCAPE, "PERMISSION_CLEAR_LANDSCAPE",
{GAME_COMMAND_CLEAR_SCENERY}},
{STR_ACTION_GUEST, "PERMISSION_GUEST",
{GAME_COMMAND_SET_GUEST_NAME}},
{STR_ACTION_STAFF, "PERMISSION_STAFF",
{GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, GAME_COMMAND_SET_STAFF_PATROL, GAME_COMMAND_FIRE_STAFF_MEMBER,
GAME_COMMAND_SET_STAFF_ORDER, GAME_COMMAND_SET_STAFF_COLOUR, GAME_COMMAND_SET_STAFF_NAME}},
{STR_ACTION_PARK_PROPERTIES, "PERMISSION_PARK_PROPERTIES",
{GAME_COMMAND_SET_PARK_NAME, GAME_COMMAND_SET_PARK_OPEN, GAME_COMMAND_SET_PARK_ENTRANCE_FEE,
GAME_COMMAND_SET_LAND_OWNERSHIP, GAME_COMMAND_BUY_LAND_RIGHTS, GAME_COMMAND_PLACE_PARK_ENTRANCE,
GAME_COMMAND_REMOVE_PARK_ENTRANCE}},
{STR_ACTION_PARK_FUNDING, "PERMISSION_PARK_FUNDING",
{GAME_COMMAND_SET_CURRENT_LOAN, GAME_COMMAND_SET_RESEARCH_FUNDING, GAME_COMMAND_START_MARKETING_CAMPAIGN}},
{STR_ACTION_KICK_PLAYER, "PERMISSION_KICK_PLAYER",
{GAME_COMMAND_KICK_PLAYER}},
{STR_ACTION_MODIFY_GROUPS, "PERMISSION_MODIFY_GROUPS",
{GAME_COMMAND_MODIFY_GROUPS}},
{STR_ACTION_SET_PLAYER_GROUP, "PERMISSION_SET_PLAYER_GROUP",
{GAME_COMMAND_SET_PLAYER_GROUP}},
{STR_ACTION_CHEAT, "PERMISSION_CHEAT",
{GAME_COMMAND_CHEAT}},
{STR_ACTION_TOGGLE_SCENERY_CLUSTER, "PERMISSION_TOGGLE_SCENERY_CLUSTER",
{-2}}
};
};
@ -354,7 +393,10 @@ private:
struct GameCommand
{
GameCommand(uint32 t, uint32* args, uint8 p, uint8 cb) { tick = t, eax = args[0], ebx = args[1], ecx = args[2], edx = args[3], esi = args[4], edi = args[5], ebp = args[6]; playerid = p; callback = cb; };
GameCommand(uint32 t, uint32* args, uint8 p, uint8 cb) {
tick = t; eax = args[0]; ebx = args[1]; ecx = args[2]; edx = args[3];
esi = args[4]; edi = args[5]; ebp = args[6]; playerid = p; callback = cb;
}
uint32 tick;
uint32 eax, ebx, ecx, edx, esi, edi, ebp;
uint8 playerid;