mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-27 08:29:11 +00:00
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "../../macros.h"
|
||||
#include "../../string.h"
|
||||
#include "../../helpers.hpp"
|
||||
#include "../network_data.h"
|
||||
|
||||
#include "packet.h"
|
||||
|
||||
@@ -24,7 +26,8 @@ extern void NORETURN CDECL error(const char *str, ...);
|
||||
*/
|
||||
Packet *NetworkSend_Init(const PacketType type)
|
||||
{
|
||||
Packet *packet = malloc(sizeof(Packet));
|
||||
Packet *packet;
|
||||
MallocT(&packet, 1);
|
||||
/* An error is inplace here, because it simply means we ran out of memory. */
|
||||
if (packet == NULL) error("Failed to allocate Packet");
|
||||
|
||||
@@ -109,7 +112,7 @@ void NetworkSend_string(Packet *packet, const char* data)
|
||||
*/
|
||||
|
||||
|
||||
extern uint CloseConnection(NetworkClientState *cs);
|
||||
extern NetworkRecvStatus CloseConnection(NetworkClientState *cs);
|
||||
|
||||
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
|
||||
static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include "../network_data.h"
|
||||
#include "packet.h"
|
||||
#include "tcp.h"
|
||||
#include "../../helpers.hpp"
|
||||
|
||||
/**
|
||||
* @file tcp.c Basic functions to receive and send TCP packets.
|
||||
@@ -99,7 +100,7 @@ bool NetworkSend_Packets(NetworkClientState *cs)
|
||||
|
||||
p = cs->packet_queue;
|
||||
while (p != NULL) {
|
||||
res = send(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
|
||||
res = send(cs->socket, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
|
||||
if (res == -1) {
|
||||
int err = GET_LAST_ERROR();
|
||||
if (err != EWOULDBLOCK) {
|
||||
@@ -148,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
|
||||
if (cs->socket == INVALID_SOCKET) return NULL;
|
||||
|
||||
if (cs->packet_recv == NULL) {
|
||||
cs->packet_recv = malloc(sizeof(Packet));
|
||||
MallocT(&cs->packet_recv, 1);
|
||||
if (cs->packet_recv == NULL) error("Failed to allocate packet");
|
||||
/* Set pos to zero! */
|
||||
cs->packet_recv->pos = 0;
|
||||
@@ -161,7 +162,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
|
||||
if (p->pos < sizeof(PacketSize)) {
|
||||
while (p->pos < sizeof(PacketSize)) {
|
||||
/* Read the size of the packet */
|
||||
res = recv(cs->socket, p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
|
||||
res = recv(cs->socket, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
|
||||
if (res == -1) {
|
||||
int err = GET_LAST_ERROR();
|
||||
if (err != EWOULDBLOCK) {
|
||||
@@ -191,7 +192,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
|
||||
|
||||
/* Read rest of packet */
|
||||
while (p->pos < p->size) {
|
||||
res = recv(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
|
||||
res = recv(cs->socket, (char*)p->buffer + p->pos, p->size - p->pos, 0);
|
||||
if (res == -1) {
|
||||
int err = GET_LAST_ERROR();
|
||||
if (err != EWOULDBLOCK) {
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "../../debug.h"
|
||||
#include "../../macros.h"
|
||||
#include "../../helpers.hpp"
|
||||
#include "packet.h"
|
||||
#include "udp.h"
|
||||
|
||||
@@ -92,7 +93,7 @@ void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in
|
||||
NetworkSend_FillPacketSize(p);
|
||||
|
||||
/* Send the buffer */
|
||||
res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
|
||||
res = sendto(udp, (const char*)p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
|
||||
|
||||
/* Check for any errors, but ignore it otherwise */
|
||||
if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR());
|
||||
@@ -114,7 +115,7 @@ void NetworkUDPReceive(const SOCKET udp)
|
||||
client_len = sizeof(client_addr);
|
||||
|
||||
/* Try to receive anything */
|
||||
nbytes = recvfrom(udp, p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
|
||||
nbytes = recvfrom(udp, (char*)p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
|
||||
|
||||
/* We got some bytes for the base header of the packet. */
|
||||
if (nbytes > 2) {
|
||||
@@ -256,7 +257,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
|
||||
uint num_grfs = NetworkRecv_uint8(cs, p);
|
||||
|
||||
for (i = 0; i < num_grfs; i++) {
|
||||
c = calloc(1, sizeof(*c));
|
||||
CallocT(&c, 1);
|
||||
NetworkRecv_GRFIdentifier(cs, p, c);
|
||||
HandleIncomingNetworkGameInfoGRFConfig(c);
|
||||
|
||||
@@ -290,7 +291,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
|
||||
info->map_width = NetworkRecv_uint16(cs, p);
|
||||
info->map_height = NetworkRecv_uint16(cs, p);
|
||||
info->map_set = NetworkRecv_uint8 (cs, p);
|
||||
info->dedicated = NetworkRecv_uint8 (cs, p);
|
||||
info->dedicated = (NetworkRecv_uint8 (cs, p) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,9 +7,9 @@
|
||||
extern const char _openttd_revision[];
|
||||
#elif defined(WITH_REV_HACK)
|
||||
#define WITH_REV
|
||||
const char _openttd_revision[] = WITH_REV_HACK;
|
||||
extern const char _openttd_revision[] = WITH_REV_HACK;
|
||||
#else
|
||||
const char _openttd_revision[] = NOREV_STRING;
|
||||
extern const char _openttd_revision[] = NOREV_STRING;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,6 +38,19 @@
|
||||
#include <stdarg.h> /* va_list */
|
||||
#include "../md5.h"
|
||||
|
||||
// global variables (declared in network_data.h)
|
||||
CommandPacket *_local_command_queue;
|
||||
|
||||
SOCKET _udp_client_socket; // udp client socket
|
||||
SOCKET _udp_server_socket; // udp server socket
|
||||
SOCKET _udp_master_socket; // udp master socket
|
||||
|
||||
// Here we keep track of the clients
|
||||
// (and the client uses [0] for his own communication)
|
||||
NetworkClientState _clients[MAX_CLIENTS];
|
||||
|
||||
|
||||
|
||||
// The listen socket for the server
|
||||
static SOCKET _listensocket;
|
||||
|
||||
@@ -277,7 +290,7 @@ char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last)
|
||||
STR_NETWORK_ERR_CLIENT_SERVER_FULL
|
||||
};
|
||||
|
||||
if (err >= lengthof(network_error_strings)) err = 0;
|
||||
if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;
|
||||
|
||||
return GetString(buf, network_error_strings[err], last);
|
||||
}
|
||||
@@ -729,7 +742,7 @@ static void NetworkAcceptClients(void)
|
||||
p->buffer[0] = p->size & 0xFF;
|
||||
p->buffer[1] = p->size >> 8;
|
||||
|
||||
send(s, p->buffer, p->size, 0);
|
||||
send(s, (const char*)p->buffer, p->size, 0);
|
||||
closesocket(s);
|
||||
|
||||
free(p);
|
||||
@@ -750,7 +763,7 @@ static void NetworkAcceptClients(void)
|
||||
p->buffer[0] = p->size & 0xFF;
|
||||
p->buffer[1] = p->size >> 8;
|
||||
|
||||
send(s, p->buffer, p->size, 0);
|
||||
send(s, (const char*)p->buffer, p->size, 0);
|
||||
closesocket(s);
|
||||
|
||||
free(p);
|
||||
@@ -1032,7 +1045,7 @@ bool NetworkServerStart(void)
|
||||
_network_own_client_index = NETWORK_SERVER_INDEX;
|
||||
|
||||
/* Non-dedicated server will always be player #1 */
|
||||
if (!_network_dedicated) _network_playas = 0;
|
||||
if (!_network_dedicated) _network_playas = PLAYER_FIRST;
|
||||
|
||||
_network_clients_connected = 0;
|
||||
|
||||
|
@@ -59,7 +59,7 @@ typedef struct NetworkClientInfo {
|
||||
uint16 client_index; // Index of the client (same as ClientState->index)
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH]; // Name of the client
|
||||
byte client_lang; // The language of the client
|
||||
byte client_playas; // As which player is this client playing (PlayerID)
|
||||
PlayerID client_playas; // As which player is this client playing (PlayerID)
|
||||
uint32 client_ip; // IP-address of the client (so he can be banned)
|
||||
Date join_date; // Gamedate the player has joined
|
||||
char unique_id[NETWORK_NAME_LENGTH]; // Every play sends an unique id so we can indentify him
|
||||
@@ -188,7 +188,6 @@ bool NetworkClientConnectGame(const char *host, uint16 port);
|
||||
void NetworkReboot(void);
|
||||
void NetworkDisconnect(void);
|
||||
|
||||
VARDEF bool _networking; ///< are we in networking mode?
|
||||
VARDEF bool _network_server; ///< network-server is active
|
||||
VARDEF bool _network_available; ///< is network mode available?
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "../console.h"
|
||||
#include "../variables.h"
|
||||
#include "../ai/ai.h"
|
||||
|
||||
#include "../helpers.hpp"
|
||||
|
||||
// This file handles all the client-commands
|
||||
|
||||
@@ -286,14 +286,14 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
||||
|
||||
if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
|
||||
byte total;
|
||||
byte current;
|
||||
PlayerID current;
|
||||
|
||||
total = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
|
||||
// There is no data at all..
|
||||
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||
|
||||
current = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
current = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||
|
||||
NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
|
||||
@@ -325,7 +325,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
|
||||
{
|
||||
NetworkClientInfo *ci;
|
||||
uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
|
||||
PlayerID playas = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
PlayerID playas = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
char name[NETWORK_NAME_LENGTH];
|
||||
char unique_id[NETWORK_NAME_LENGTH];
|
||||
|
||||
@@ -375,7 +375,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
|
||||
|
||||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
|
||||
{
|
||||
NetworkErrorCode error = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
NetworkErrorCode error = (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
|
||||
switch (error) {
|
||||
/* We made an error in the protocol, and our connection is closed.... */
|
||||
@@ -410,7 +410,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
|
||||
|
||||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
|
||||
{
|
||||
NetworkPasswordType type = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
NetworkPasswordType type = (NetworkPasswordType)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
|
||||
switch (type) {
|
||||
case NETWORK_GAME_PASSWORD:
|
||||
@@ -570,8 +570,9 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
|
||||
|
||||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
|
||||
{
|
||||
CommandPacket *cp = malloc(sizeof(CommandPacket));
|
||||
cp->player = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
CommandPacket *cp;
|
||||
MallocT(&cp, 1);
|
||||
cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
|
||||
cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);
|
||||
cp->p2 = NetworkRecv_uint32(MY_CLIENT, p);
|
||||
@@ -601,9 +602,9 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
|
||||
char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN];
|
||||
const NetworkClientInfo *ci = NULL, *ci_to;
|
||||
|
||||
NetworkAction action = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
NetworkAction action = (NetworkAction)NetworkRecv_uint8(MY_CLIENT, p);
|
||||
uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
|
||||
bool self_send = NetworkRecv_uint8(MY_CLIENT, p);
|
||||
bool self_send = (NetworkRecv_uint8(MY_CLIENT, p) != 0);
|
||||
NetworkRecv_string(MY_CLIENT, p, msg, MAX_TEXT_MSG_LEN);
|
||||
|
||||
ci_to = NetworkFindClientInfoFromIndex(index);
|
||||
@@ -623,7 +624,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
|
||||
if (!IsValidPlayer(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
|
||||
/* fallthrough */
|
||||
case NETWORK_ACTION_CHAT_COMPANY: {
|
||||
StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : STR_NETWORK_SPECTATORS;
|
||||
StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : (uint16)STR_NETWORK_SPECTATORS;
|
||||
|
||||
GetString(name, str, lastof(name));
|
||||
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
|
||||
@@ -649,7 +650,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
|
||||
NetworkClientInfo *ci;
|
||||
|
||||
index = NetworkRecv_uint16(MY_CLIENT, p);
|
||||
GetNetworkErrorMsg(str, NetworkRecv_uint8(MY_CLIENT, p), lastof(str));
|
||||
GetNetworkErrorMsg(str, (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p), lastof(str));
|
||||
|
||||
ci = NetworkFindClientInfoFromIndex(index);
|
||||
if (ci != NULL) {
|
||||
|
@@ -9,11 +9,13 @@
|
||||
#include "network_client.h"
|
||||
#include "../command.h"
|
||||
#include "../callback_table.h"
|
||||
#include "../helpers.hpp"
|
||||
|
||||
// Add a command to the local command queue
|
||||
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
|
||||
{
|
||||
CommandPacket* new_cp = malloc(sizeof(*new_cp));
|
||||
CommandPacket* new_cp;
|
||||
MallocT(&new_cp, 1);
|
||||
|
||||
*new_cp = *cp;
|
||||
|
||||
@@ -29,7 +31,8 @@ void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
|
||||
// Prepare a DoCommand to be send over the network
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
|
||||
{
|
||||
CommandPacket *c = malloc(sizeof(CommandPacket));
|
||||
CommandPacket *c;
|
||||
MallocT(&c, 1);
|
||||
byte temp_callback;
|
||||
|
||||
c->player = _local_player;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
typedef struct CommandPacket {
|
||||
struct CommandPacket *next;
|
||||
PlayerID player; /// player that is executing the command
|
||||
PlayerByte player; /// player that is executing the command
|
||||
uint32 cmd; /// command being executed
|
||||
uint32 p1; /// parameter p1
|
||||
uint32 p2; /// parameter p2
|
||||
@@ -120,15 +120,17 @@ typedef enum {
|
||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain player (Private)
|
||||
} DestType;
|
||||
|
||||
CommandPacket *_local_command_queue;
|
||||
// following externs are instantiated at network.cpp
|
||||
extern CommandPacket *_local_command_queue;
|
||||
|
||||
SOCKET _udp_client_socket; // udp client socket
|
||||
SOCKET _udp_server_socket; // udp server socket
|
||||
SOCKET _udp_master_socket; // udp master socket
|
||||
extern SOCKET _udp_client_socket; // udp client socket
|
||||
extern SOCKET _udp_server_socket; // udp server socket
|
||||
extern SOCKET _udp_master_socket; // udp master socket
|
||||
|
||||
// Here we keep track of the clients
|
||||
// (and the client uses [0] for his own communication)
|
||||
NetworkClientState _clients[MAX_CLIENTS];
|
||||
extern NetworkClientState _clients[MAX_CLIENTS];
|
||||
|
||||
#define DEREF_CLIENT(i) (&_clients[i])
|
||||
// This returns the NetworkClientInfo from a NetworkClientState
|
||||
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients])
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "../debug.h"
|
||||
#include "network_data.h"
|
||||
#include "../newgrf_config.h"
|
||||
#include "../helpers.hpp"
|
||||
|
||||
// This file handles the GameList
|
||||
// Also, it handles the request to a server for data about the server
|
||||
@@ -25,7 +26,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
|
||||
prev_item = item;
|
||||
}
|
||||
|
||||
item = malloc(sizeof(*item));
|
||||
MallocT(&item, 1);
|
||||
memset(item, 0, sizeof(*item));
|
||||
item->next = NULL;
|
||||
item->ip = ip;
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "../string.h"
|
||||
#include "../town.h"
|
||||
#include "../newgrf.h"
|
||||
#include "../helpers.hpp"
|
||||
|
||||
#define BGC 5
|
||||
#define BTC 15
|
||||
@@ -166,7 +167,7 @@ static void BuildNetworkGameList(network_ql_d *nqld)
|
||||
|
||||
/* Create temporary array of games to use for listing */
|
||||
free(nqld->sort_list);
|
||||
nqld->sort_list = malloc(n * sizeof(nqld->sort_list[0]));
|
||||
MallocT(&nqld->sort_list, n);
|
||||
if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list");
|
||||
nqld->l.list_length = n;
|
||||
|
||||
@@ -221,7 +222,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||
nd->server = NULL;
|
||||
|
||||
WP(w, network_ql_d).sort_list = NULL;
|
||||
ld->flags = VL_REBUILD | (_ng_sorting.order << (VL_DESC - 1));
|
||||
ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
|
||||
ld->sort_type = _ng_sorting.criteria;
|
||||
break;
|
||||
|
||||
@@ -787,19 +788,19 @@ static void ShowNetworkStartServerWindow(void)
|
||||
InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160);
|
||||
}
|
||||
|
||||
static byte NetworkLobbyFindCompanyIndex(byte pos)
|
||||
static PlayerID NetworkLobbyFindCompanyIndex(byte pos)
|
||||
{
|
||||
byte i;
|
||||
PlayerID i;
|
||||
|
||||
/* Scroll through all _network_player_info and get the 'pos' item
|
||||
that is not empty */
|
||||
for (i = 0; i < MAX_PLAYERS; i++) {
|
||||
for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
||||
if (_network_player_info[i].company_name[0] != '\0') {
|
||||
if (pos-- == 0) return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return PLAYER_FIRST;
|
||||
}
|
||||
|
||||
/* uses network_d WP macro */
|
||||
@@ -809,7 +810,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
nd->company = (byte)-1;
|
||||
nd->company = INVALID_PLAYER;
|
||||
break;
|
||||
|
||||
case WE_PAINT: {
|
||||
@@ -919,7 +920,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
|
||||
if (id_v >= w->vscroll.cap) return;
|
||||
|
||||
id_v += w->vscroll.pos;
|
||||
nd->company = (id_v >= nd->server->info.companies_on) ? (byte)-1 : NetworkLobbyFindCompanyIndex(id_v);
|
||||
nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
|
||||
SetWindowDirty(w);
|
||||
} break;
|
||||
case 7: /* Join company */
|
||||
@@ -1411,7 +1412,7 @@ static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
|
||||
/* Draw nice progress bar :) */
|
||||
DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, 0);
|
||||
DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
|
||||
} break;
|
||||
|
||||
case WE_CLICK:
|
||||
@@ -1465,9 +1466,9 @@ static void SendChat(const char *buf, DestType type, byte dest)
|
||||
{
|
||||
if (buf[0] == '\0') return;
|
||||
if (!_network_server) {
|
||||
SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + type, type, dest, buf);
|
||||
SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
|
||||
} else {
|
||||
NetworkServer_HandleChat(NETWORK_ACTION_CHAT + type, type, dest, buf, NETWORK_SERVER_INDEX);
|
||||
NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1635,7 +1636,7 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
case 3: { /* Send */
|
||||
DestType type = GB(WP(w, querystr_d).caption, 0, 8);
|
||||
DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
|
||||
byte dest = GB(WP(w, querystr_d).caption, 8, 8);
|
||||
SendChat(WP(w, querystr_d).text.buf, type, dest);
|
||||
} /* FALLTHROUGH */
|
||||
@@ -1654,7 +1655,7 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
|
||||
_chat_tab_completion_active = false;
|
||||
switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) {
|
||||
case 1: { /* Return */
|
||||
DestType type = GB(WP(w, querystr_d).caption, 0, 8);
|
||||
DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
|
||||
byte dest = GB(WP(w, querystr_d).caption, 8, 8);
|
||||
SendChat(WP(w, querystr_d).text.buf, type, dest);
|
||||
} /* FALLTHROUGH */
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include "network_data.h"
|
||||
|
||||
void ShowNetworkNeedPassword(NetworkPasswordType npt);
|
||||
void ShowNetworkGiveMoneyWindow(byte player); // PlayerID
|
||||
void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
|
||||
void ShowNetworkChatQueryWindow(DestType type, byte dest);
|
||||
void ShowJoinStatusWindow(void);
|
||||
void ShowNetworkGameWindow(void);
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#include "../station.h"
|
||||
#include "../variables.h"
|
||||
#include "../genworld.h"
|
||||
#include "../helpers.hpp"
|
||||
|
||||
// This file handles all the server-commands
|
||||
|
||||
@@ -571,7 +572,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
||||
char name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
char unique_id[NETWORK_NAME_LENGTH];
|
||||
NetworkClientInfo *ci;
|
||||
byte playas;
|
||||
PlayerID playas;
|
||||
NetworkLanguage client_lang;
|
||||
char client_revision[NETWORK_REVISION_LENGTH];
|
||||
|
||||
@@ -588,8 +589,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
||||
#endif
|
||||
|
||||
NetworkRecv_string(cs, p, name, sizeof(name));
|
||||
playas = NetworkRecv_uint8(cs, p);
|
||||
client_lang = NetworkRecv_uint8(cs, p);
|
||||
playas = (Owner)NetworkRecv_uint8(cs, p);
|
||||
client_lang = (NetworkLanguage)NetworkRecv_uint8(cs, p);
|
||||
NetworkRecv_string(cs, p, unique_id, sizeof(unique_id));
|
||||
|
||||
if (cs->has_quit) return;
|
||||
@@ -654,7 +655,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
|
||||
char password[NETWORK_PASSWORD_LENGTH];
|
||||
const NetworkClientInfo *ci;
|
||||
|
||||
type = NetworkRecv_uint8(cs, p);
|
||||
type = (NetworkPasswordType)NetworkRecv_uint8(cs, p);
|
||||
NetworkRecv_string(cs, p, password, sizeof(password));
|
||||
|
||||
if (cs->status == STATUS_INACTIVE && type == NETWORK_GAME_PASSWORD) {
|
||||
@@ -792,7 +793,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||
const NetworkClientInfo *ci;
|
||||
byte callback;
|
||||
|
||||
CommandPacket *cp = malloc(sizeof(CommandPacket));
|
||||
CommandPacket *cp;
|
||||
MallocT(&cp, 1);
|
||||
|
||||
// The client was never joined.. so this is impossible, right?
|
||||
// Ignore the packet, give the client a warning, and close his connection
|
||||
@@ -801,7 +803,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||
return;
|
||||
}
|
||||
|
||||
cp->player = NetworkRecv_uint8(cs, p);
|
||||
cp->player = (Owner)NetworkRecv_uint8(cs, p);
|
||||
cp->cmd = NetworkRecv_uint32(cs, p);
|
||||
cp->p1 = NetworkRecv_uint32(cs, p);
|
||||
cp->p2 = NetworkRecv_uint32(cs, p);
|
||||
@@ -851,7 +853,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||
/* XXX - Execute the command as a valid player. Normally this would be done by a
|
||||
* spectator, but that is not allowed any commands. So do an impersonation. The drawback
|
||||
* of this is that the first company's last_built_tile is also updated... */
|
||||
cp->player = 0;
|
||||
cp->player = OWNER_BEGIN;
|
||||
cp->p2 = cs - _clients; // XXX - UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
|
||||
}
|
||||
|
||||
@@ -890,7 +892,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
|
||||
NetworkClientState *new_cs;
|
||||
char str[100];
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
NetworkErrorCode errorno = NetworkRecv_uint8(cs, p);
|
||||
NetworkErrorCode errorno = (NetworkErrorCode)NetworkRecv_uint8(cs, p);
|
||||
|
||||
// The client was never joined.. thank the client for the packet, but ignore it
|
||||
if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
|
||||
@@ -1044,7 +1046,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
if (ci != NULL && show_local) {
|
||||
if (from_index == NETWORK_SERVER_INDEX) {
|
||||
char name[NETWORK_NAME_LENGTH];
|
||||
StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : STR_NETWORK_SPECTATORS;
|
||||
StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : (uint16)STR_NETWORK_SPECTATORS;
|
||||
GetString(name, str, lastof(name));
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
|
||||
} else {
|
||||
@@ -1073,8 +1075,8 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
|
||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
|
||||
{
|
||||
NetworkAction action = NetworkRecv_uint8(cs, p);
|
||||
DestType desttype = NetworkRecv_uint8(cs, p);
|
||||
NetworkAction action = (NetworkAction)NetworkRecv_uint8(cs, p);
|
||||
DestType desttype = (DestType)NetworkRecv_uint8(cs, p);
|
||||
int dest = NetworkRecv_uint8(cs, p);
|
||||
char msg[MAX_TEXT_MSG_LEN];
|
||||
|
||||
|
@@ -335,7 +335,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_GET_NEWGRFS)
|
||||
* the current list and do not send the other data.
|
||||
* The name could be an empty string, if so take the filename. */
|
||||
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
|
||||
min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, NETWORK_GRF_NAME_LENGTH);
|
||||
min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
|
||||
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user