(svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
parent
026afc097a
commit
bae02e8c67
@ -1,121 +0,0 @@
|
|||||||
/* $Id$ */
|
|
||||||
|
|
||||||
/** @file network_data.h Internal functions. */
|
|
||||||
|
|
||||||
#ifndef NETWORK_DATA_H
|
|
||||||
#define NETWORK_DATA_H
|
|
||||||
|
|
||||||
#include "../openttd.h"
|
|
||||||
#include "../console_type.h"
|
|
||||||
#include "network.h"
|
|
||||||
#include "network_internal.h"
|
|
||||||
|
|
||||||
// Is the network enabled?
|
|
||||||
#ifdef ENABLE_NETWORK
|
|
||||||
|
|
||||||
#include "core/os_abstraction.h"
|
|
||||||
#include "core/core.h"
|
|
||||||
#include "core/config.h"
|
|
||||||
#include "core/packet.h"
|
|
||||||
#include "core/tcp.h"
|
|
||||||
|
|
||||||
#define MAX_TEXT_MSG_LEN 1024 /* long long long long sentences :-) */
|
|
||||||
|
|
||||||
// The client-info-server-index is always 1
|
|
||||||
#define NETWORK_SERVER_INDEX 1
|
|
||||||
#define NETWORK_EMPTY_INDEX 0
|
|
||||||
|
|
||||||
enum MapPacket {
|
|
||||||
MAP_PACKET_START,
|
|
||||||
MAP_PACKET_NORMAL,
|
|
||||||
MAP_PACKET_END,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum NetworkErrorCode {
|
|
||||||
NETWORK_ERROR_GENERAL, // Try to use thisone like never
|
|
||||||
|
|
||||||
// Signals from clients
|
|
||||||
NETWORK_ERROR_DESYNC,
|
|
||||||
NETWORK_ERROR_SAVEGAME_FAILED,
|
|
||||||
NETWORK_ERROR_CONNECTION_LOST,
|
|
||||||
NETWORK_ERROR_ILLEGAL_PACKET,
|
|
||||||
NETWORK_ERROR_NEWGRF_MISMATCH,
|
|
||||||
|
|
||||||
// Signals from servers
|
|
||||||
NETWORK_ERROR_NOT_AUTHORIZED,
|
|
||||||
NETWORK_ERROR_NOT_EXPECTED,
|
|
||||||
NETWORK_ERROR_WRONG_REVISION,
|
|
||||||
NETWORK_ERROR_NAME_IN_USE,
|
|
||||||
NETWORK_ERROR_WRONG_PASSWORD,
|
|
||||||
NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND
|
|
||||||
NETWORK_ERROR_KICKED,
|
|
||||||
NETWORK_ERROR_CHEATER,
|
|
||||||
NETWORK_ERROR_FULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Actions that can be used for NetworkTextMessage
|
|
||||||
enum NetworkAction {
|
|
||||||
NETWORK_ACTION_JOIN,
|
|
||||||
NETWORK_ACTION_LEAVE,
|
|
||||||
NETWORK_ACTION_SERVER_MESSAGE,
|
|
||||||
NETWORK_ACTION_CHAT,
|
|
||||||
NETWORK_ACTION_CHAT_COMPANY,
|
|
||||||
NETWORK_ACTION_CHAT_CLIENT,
|
|
||||||
NETWORK_ACTION_GIVE_MONEY,
|
|
||||||
NETWORK_ACTION_NAME_CHANGE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum NetworkPasswordType {
|
|
||||||
NETWORK_GAME_PASSWORD,
|
|
||||||
NETWORK_COMPANY_PASSWORD,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DestType {
|
|
||||||
DESTTYPE_BROADCAST, ///< Send message/notice to all players (All)
|
|
||||||
DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team)
|
|
||||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain player (Private)
|
|
||||||
};
|
|
||||||
|
|
||||||
// following externs are instantiated at network.cpp
|
|
||||||
extern CommandPacket *_local_command_queue;
|
|
||||||
|
|
||||||
// Here we keep track of the clients
|
|
||||||
// (and the client uses [0] for his own communication)
|
|
||||||
extern NetworkTCPSocketHandler _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])
|
|
||||||
|
|
||||||
// Macros to make life a bit more easier
|
|
||||||
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
|
|
||||||
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command()
|
|
||||||
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
|
||||||
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkTCPSocketHandler *cs, Packet *p)
|
|
||||||
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkTCPSocketHandler *cs)
|
|
||||||
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command
|
|
||||||
|
|
||||||
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
|
|
||||||
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
|
|
||||||
|
|
||||||
#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != endof(_clients) && cs->IsConnected(); cs++)
|
|
||||||
#define FOR_ALL_ACTIVE_CLIENT_INFOS(ci) for (ci = _network_client_info; ci != endof(_network_client_info); ci++) if (ci->client_index != NETWORK_EMPTY_INDEX)
|
|
||||||
|
|
||||||
void NetworkExecuteCommand(CommandPacket *cp);
|
|
||||||
void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp);
|
|
||||||
|
|
||||||
// from network.c
|
|
||||||
void NetworkCloseClient(NetworkTCPSocketHandler *cs);
|
|
||||||
void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...);
|
|
||||||
void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs);
|
|
||||||
uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs);
|
|
||||||
byte NetworkGetCurrentLanguageIndex();
|
|
||||||
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
|
|
||||||
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip);
|
|
||||||
NetworkTCPSocketHandler *NetworkFindClientStateFromIndex(uint16 client_index);
|
|
||||||
unsigned long NetworkResolveHost(const char *hostname);
|
|
||||||
char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last);
|
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
|
||||||
|
|
||||||
#endif /* NETWORK_DATA_H */
|
|
@ -0,0 +1,63 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file network_internal.h Variables and function used internally. */
|
||||||
|
|
||||||
|
#ifndef NETWORK_FUNC_H
|
||||||
|
#define NETWORK_FUNC_H
|
||||||
|
|
||||||
|
#ifdef ENABLE_NETWORK
|
||||||
|
|
||||||
|
#include "network_type.h"
|
||||||
|
#include "../console_type.h"
|
||||||
|
|
||||||
|
extern NetworkGameInfo _network_game_info;
|
||||||
|
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
|
||||||
|
extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
|
||||||
|
|
||||||
|
extern uint16 _network_own_client_index;
|
||||||
|
extern uint16 _redirect_console_to_client;
|
||||||
|
extern bool _network_need_advertise;
|
||||||
|
extern uint32 _network_last_advertise_frame;
|
||||||
|
extern uint8 _network_reconnect;
|
||||||
|
extern char *_network_host_list[10];
|
||||||
|
extern char *_network_ban_list[25];
|
||||||
|
|
||||||
|
byte NetworkSpectatorCount();
|
||||||
|
void CheckMinPlayers();
|
||||||
|
void NetworkUpdatePlayerName();
|
||||||
|
bool NetworkCompanyHasPlayers(PlayerID company);
|
||||||
|
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
|
||||||
|
void NetworkReboot();
|
||||||
|
void NetworkDisconnect();
|
||||||
|
void NetworkGameLoop();
|
||||||
|
void NetworkUDPGameLoop();
|
||||||
|
void NetworkUDPCloseAll();
|
||||||
|
void ParseConnectionString(const char **player, const char **port, char *connection_string);
|
||||||
|
void NetworkStartDebugLog(const char *hostname, uint16 port);
|
||||||
|
void NetworkPopulateCompanyInfo();
|
||||||
|
|
||||||
|
void NetworkUpdateClientInfo(uint16 client_index);
|
||||||
|
bool NetworkClientConnectGame(const char *host, uint16 port);
|
||||||
|
void NetworkClientSendRcon(const char *password, const char *command);
|
||||||
|
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg);
|
||||||
|
void NetworkClientSetPassword();
|
||||||
|
|
||||||
|
/*** Commands ran by the server ***/
|
||||||
|
void NetworkServerMonthlyLoop();
|
||||||
|
void NetworkServerYearlyLoop();
|
||||||
|
void NetworkServerChangeOwner(PlayerID current_player, PlayerID new_player);
|
||||||
|
void NetworkServerShowStatusToConsole();
|
||||||
|
bool NetworkServerStart();
|
||||||
|
|
||||||
|
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
|
||||||
|
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip);
|
||||||
|
const char* GetPlayerIP(const NetworkClientInfo *ci);
|
||||||
|
|
||||||
|
void NetworkServerSendRcon(uint16 client_index, ConsoleColour colour_code, const char *string);
|
||||||
|
void NetworkServerSendError(uint16 client_index, NetworkErrorCode error);
|
||||||
|
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, uint16 from_index);
|
||||||
|
|
||||||
|
#define FOR_ALL_ACTIVE_CLIENT_INFOS(ci) for (ci = _network_client_info; ci != endof(_network_client_info); ci++) if (ci->client_index != NETWORK_EMPTY_INDEX)
|
||||||
|
|
||||||
|
#endif /* ENABLE_NETWORK */
|
||||||
|
#endif /* NETWORK_FUNC_H */
|
@ -0,0 +1,108 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file network_internal.h Variables and function used internally. */
|
||||||
|
|
||||||
|
#ifndef NETWORK_TYPE_H
|
||||||
|
#define NETWORK_TYPE_H
|
||||||
|
|
||||||
|
#ifdef ENABLE_NETWORK
|
||||||
|
|
||||||
|
#include "../player_type.h"
|
||||||
|
#include "../economy_type.h"
|
||||||
|
#include "core/config.h"
|
||||||
|
#include "core/game.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
/**
|
||||||
|
* How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
|
||||||
|
* players that can really play.. so.. a max of 4 spectators.. gives us..
|
||||||
|
* MAX_PLAYERS + 3
|
||||||
|
*/
|
||||||
|
MAX_CLIENTS = MAX_PLAYERS + 3,
|
||||||
|
|
||||||
|
/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
|
||||||
|
MAX_CLIENT_INFO = MAX_CLIENTS + 1,
|
||||||
|
|
||||||
|
/** Maximum number of internet interfaces supported. */
|
||||||
|
MAX_INTERFACES = 9,
|
||||||
|
|
||||||
|
/** How many vehicle/station types we put over the network */
|
||||||
|
NETWORK_VEHICLE_TYPES = 5,
|
||||||
|
NETWORK_STATION_TYPES = 5,
|
||||||
|
|
||||||
|
NETWORK_SERVER_INDEX = 1,
|
||||||
|
NETWORK_EMPTY_INDEX = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NetworkPlayerInfo {
|
||||||
|
char company_name[NETWORK_NAME_LENGTH]; ///< Company name
|
||||||
|
char password[NETWORK_PASSWORD_LENGTH]; ///< The password for the player
|
||||||
|
Year inaugurated_year; ///< What year the company started in
|
||||||
|
Money company_value; ///< The company value
|
||||||
|
Money money; ///< The amount of money the company has
|
||||||
|
Money income; ///< How much did the company earned last year
|
||||||
|
uint16 performance; ///< What was his performance last month?
|
||||||
|
bool use_password; ///< Is there a password
|
||||||
|
uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; ///< How many vehicles are there of this type?
|
||||||
|
uint16 num_station[NETWORK_STATION_TYPES]; ///< How many stations are there of this type?
|
||||||
|
char players[NETWORK_PLAYERS_LENGTH]; ///< The players that control this company (Name1, name2, ..)
|
||||||
|
uint16 months_empty; ///< How many months the company is empty
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
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_UNIQUE_ID_LENGTH]; ///< Every play sends an unique id so we can indentify him
|
||||||
|
};
|
||||||
|
|
||||||
|
enum NetworkPasswordType {
|
||||||
|
NETWORK_GAME_PASSWORD,
|
||||||
|
NETWORK_COMPANY_PASSWORD,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DestType {
|
||||||
|
DESTTYPE_BROADCAST, ///< Send message/notice to all players (All)
|
||||||
|
DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team)
|
||||||
|
DESTTYPE_CLIENT, ///< Send message/notice to only a certain player (Private)
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Actions that can be used for NetworkTextMessage */
|
||||||
|
enum NetworkAction {
|
||||||
|
NETWORK_ACTION_JOIN,
|
||||||
|
NETWORK_ACTION_LEAVE,
|
||||||
|
NETWORK_ACTION_SERVER_MESSAGE,
|
||||||
|
NETWORK_ACTION_CHAT,
|
||||||
|
NETWORK_ACTION_CHAT_COMPANY,
|
||||||
|
NETWORK_ACTION_CHAT_CLIENT,
|
||||||
|
NETWORK_ACTION_GIVE_MONEY,
|
||||||
|
NETWORK_ACTION_NAME_CHANGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum NetworkErrorCode {
|
||||||
|
NETWORK_ERROR_GENERAL, // Try to use this one like never
|
||||||
|
|
||||||
|
/* Signals from clients */
|
||||||
|
NETWORK_ERROR_DESYNC,
|
||||||
|
NETWORK_ERROR_SAVEGAME_FAILED,
|
||||||
|
NETWORK_ERROR_CONNECTION_LOST,
|
||||||
|
NETWORK_ERROR_ILLEGAL_PACKET,
|
||||||
|
NETWORK_ERROR_NEWGRF_MISMATCH,
|
||||||
|
|
||||||
|
/* Signals from servers */
|
||||||
|
NETWORK_ERROR_NOT_AUTHORIZED,
|
||||||
|
NETWORK_ERROR_NOT_EXPECTED,
|
||||||
|
NETWORK_ERROR_WRONG_REVISION,
|
||||||
|
NETWORK_ERROR_NAME_IN_USE,
|
||||||
|
NETWORK_ERROR_WRONG_PASSWORD,
|
||||||
|
NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND
|
||||||
|
NETWORK_ERROR_KICKED,
|
||||||
|
NETWORK_ERROR_CHEATER,
|
||||||
|
NETWORK_ERROR_FULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ENABLE_NETWORK */
|
||||||
|
#endif /* NETWORK_TYPE_H */
|
Loading…
Reference in New Issue