1
0
Fork 0

(svn r8445) -Cleanup: remove some @params from comments as the parameters did not exist anymore and add comments to several variables/functions.

release/0.6
rubidium 2007-01-28 20:47:25 +00:00
parent 2e984e0477
commit f72dde5236
8 changed files with 43 additions and 23 deletions

View File

@ -5,6 +5,10 @@
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
/**
* @file config.h Configuration options of the network stuff
*/
/** DNS hostname of the masterserver */ /** DNS hostname of the masterserver */
#define NETWORK_MASTER_SERVER_HOST "master.openttd.org" #define NETWORK_MASTER_SERVER_HOST "master.openttd.org"
/** Message sent to the masterserver to 'identify' this client as OpenTTD */ /** Message sent to the masterserver to 'identify' this client as OpenTTD */

View File

@ -6,6 +6,10 @@
#include "../../debug.h" #include "../../debug.h"
#include "os_abstraction.h" #include "os_abstraction.h"
/**
* @file core.cpp Functions used to initialize/shut down the core network
*/
#ifdef __MORPHOS__ #ifdef __MORPHOS__
/* the library base is required here */ /* the library base is required here */
struct Library *SocketBase = NULL; struct Library *SocketBase = NULL;
@ -13,6 +17,7 @@ struct Library *SocketBase = NULL;
/** /**
* Initializes the network core (as that is needed for some platforms * Initializes the network core (as that is needed for some platforms
* @return true if the core has been initialized, false otherwise
*/ */
bool NetworkCoreInitialize(void) bool NetworkCoreInitialize(void)
{ {

View File

@ -7,9 +7,14 @@
#include "os_abstraction.h" #include "os_abstraction.h"
/**
* @file core.h Base for all network types (UDP and TCP)
*/
bool NetworkCoreInitialize(void); bool NetworkCoreInitialize(void);
void NetworkCoreShutdown(void); void NetworkCoreShutdown(void);
/** Status of a network client; reasons why a client has quit */
typedef enum { typedef enum {
NETWORK_RECV_STATUS_OKAY, ///< Everything is okay NETWORK_RECV_STATUS_OKAY, ///< Everything is okay
NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur NETWORK_RECV_STATUS_DESYNC, ///< A desync did occur
@ -32,7 +37,10 @@ public:
bool has_quit; ///< Whether the current client has quit/send a bad packet bool has_quit; ///< Whether the current client has quit/send a bad packet
SOCKET sock; ///< The socket currently connected to SOCKET sock; ///< The socket currently connected to
public: public:
/** Create a new unbound socket */
NetworkSocketHandler() { this->sock = INVALID_SOCKET; this->has_quit = false; } NetworkSocketHandler() { this->sock = INVALID_SOCKET; this->has_quit = false; }
/** Close the socket when distructing the socket handler */
virtual ~NetworkSocketHandler() { this->Close(); } virtual ~NetworkSocketHandler() { this->Close(); }
/** Really close the socket */ /** Really close the socket */

View File

@ -10,7 +10,7 @@
#include "packet.h" #include "packet.h"
/** /**
* @file packet.h Basic functions to create, fill and read packets. * @file packet.cpp Basic functions to create, fill and read packets.
*/ */
@ -94,6 +94,8 @@ void NetworkSend_uint64(Packet *packet, uint64 data)
/** /**
* Sends a string over the network. It sends out * Sends a string over the network. It sends out
* the string + '\0'. No size-byte or something. * the string + '\0'. No size-byte or something.
* @param packet packet to send the string in
* @param data the string to send
*/ */
void NetworkSend_string(Packet *packet, const char* data) void NetworkSend_string(Packet *packet, const char* data)
{ {

View File

@ -15,7 +15,7 @@
#include "../../helpers.hpp" #include "../../helpers.hpp"
/** /**
* @file tcp.c Basic functions to receive and send TCP packets. * @file tcp.cpp Basic functions to receive and send TCP packets.
*/ */
/** Very ugly temporary hack !!! */ /** Very ugly temporary hack !!! */
@ -43,7 +43,6 @@ void NetworkTCPSocketHandler::Initialize()
* A socket can make errors. When that happens this handles what to do. * A socket can make errors. When that happens this handles what to do.
* For clients: close connection and drop back to main-menu * For clients: close connection and drop back to main-menu
* For servers: close connection and that is it * For servers: close connection and that is it
* @param cs the client to close the connection of
* @return the new status * @return the new status
* TODO: needs to be splitted when using client and server socket packets * TODO: needs to be splitted when using client and server socket packets
*/ */

View File

@ -55,18 +55,20 @@ enum {
PACKET_END ///< Must ALWAYS be on the end of this list!! (period) PACKET_END ///< Must ALWAYS be on the end of this list!! (period)
}; };
/** Packet that wraps a command */
typedef struct CommandPacket { typedef struct CommandPacket {
struct CommandPacket *next; struct CommandPacket *next; ///< the next command packet (if in queue)
PlayerByte player; ///< player that is executing the command PlayerByte player; ///< player that is executing the command
uint32 cmd; ///< command being executed uint32 cmd; ///< command being executed
uint32 p1; ///< parameter p1 uint32 p1; ///< parameter p1
uint32 p2; ///< parameter p2 uint32 p2; ///< parameter p2
TileIndex tile; ///< tile command being executed on TileIndex tile; ///< tile command being executed on
char text[80]; char text[80]; ///< possible text sent for name changes etc
uint32 frame; ///< the frame in which this packet is executed uint32 frame; ///< the frame in which this packet is executed
byte callback; ///< any callback function executed upon successful completion of the command byte callback; ///< any callback function executed upon successful completion of the command
} CommandPacket; } CommandPacket;
/** Status of a client */
typedef enum { typedef enum {
STATUS_INACTIVE, ///< The client is not connected nor active STATUS_INACTIVE, ///< The client is not connected nor active
STATUS_AUTH, ///< The client is authorized STATUS_AUTH, ///< The client is authorized
@ -81,18 +83,18 @@ typedef enum {
class NetworkTCPSocketHandler : public NetworkSocketHandler { class NetworkTCPSocketHandler : public NetworkSocketHandler {
/* TODO: rewrite into a proper class */ /* TODO: rewrite into a proper class */
public: public:
uint16 index; uint16 index; ///< Client index
uint32 last_frame; uint32 last_frame; ///< Last frame we have executed
uint32 last_frame_server; uint32 last_frame_server; ///< Last frame the server has executed
byte lag_test; // This byte is used for lag-testing the client byte lag_test; ///< Byte used for lag-testing the client
ClientStatus status; ClientStatus status; ///< Status of this client
bool writable; // is client ready to write to? bool writable; ///< Can we write to this socket?
Packet *packet_queue; // Packets that are awaiting delivery Packet *packet_queue; ///< Packets that are awaiting delivery
Packet *packet_recv; // Partially received packet Packet *packet_recv; ///< Partially received packet
CommandPacket *command_queue; // The command-queue awaiting delivery CommandPacket *command_queue; ///< The command-queue awaiting delivery
NetworkRecvStatus CloseConnection(); NetworkRecvStatus CloseConnection();
void Initialize(); void Initialize();

View File

@ -10,12 +10,11 @@
#include "udp.h" #include "udp.h"
/** /**
* @file udp.c Basic functions to receive and send UDP packets. * @file core/udp.cpp Basic functions to receive and send UDP packets.
*/ */
/** /**
* Start listening on the given host and port. * Start listening on the given host and port.
* @param udp the place where the (references to the) UDP are stored
* @param host the host (ip) to listen on * @param host the host (ip) to listen on
* @param port the port to listen on * @param port the port to listen on
* @param broadcast whether to allow broadcast sending/receiving * @param broadcast whether to allow broadcast sending/receiving
@ -69,7 +68,6 @@ bool NetworkUDPSocketHandler::Listen(const uint32 host, const uint16 port, const
/** /**
* Close the given UDP socket * Close the given UDP socket
* @param udp the socket to close
*/ */
void NetworkUDPSocketHandler::Close() void NetworkUDPSocketHandler::Close()
{ {
@ -87,7 +85,6 @@ NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection()
/** /**
* Send a packet over UDP * Send a packet over UDP
* @param udp the socket to send over
* @param p the packet to send * @param p the packet to send
* @param recv the receiver (target) of the packet * @param recv the receiver (target) of the packet
*/ */
@ -106,7 +103,6 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, const struct sockaddr_in *re
/** /**
* Receive a packet at UDP level * Receive a packet at UDP level
* @param udp the socket to receive the packet on
*/ */
void NetworkUDPSocketHandler::ReceivePackets() void NetworkUDPSocketHandler::ReceivePackets()
{ {
@ -305,7 +301,10 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
} }
} }
/* Defines a simple (switch) case for each network packet */ /**
* Defines a simple (switch) case for each network packet
* @param type the packet type to create the case for
*/
#define UDP_COMMAND(type) case type: this->NetworkPacketReceive_ ## type ## _command(p, client_addr); break; #define UDP_COMMAND(type) case type: this->NetworkPacketReceive_ ## type ## _command(p, client_addr); break;
/** /**
@ -345,12 +344,12 @@ void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, const struct sockaddr_i
} }
} }
/* /**
* Create stub implementations for all receive commands that only * Create stub implementations for all receive commands that only
* show a warning that the given command is not available for the * show a warning that the given command is not available for the
* socket where the packet came from. * socket where the packet came from.
* @param type the packet type to create the stub for
*/ */
#define DEFINE_UNAVAILABLE_UDP_RECEIVE_COMMAND(type) \ #define DEFINE_UNAVAILABLE_UDP_RECEIVE_COMMAND(type) \
void NetworkUDPSocketHandler::NetworkPacketReceive_## type ##_command(\ void NetworkUDPSocketHandler::NetworkPacketReceive_## type ##_command(\
Packet *p, const struct sockaddr_in *client_addr) { \ Packet *p, const struct sockaddr_in *client_addr) { \

View File

@ -120,8 +120,9 @@ protected:
* the grfconfig list of the NetworkGameInfo. * the grfconfig list of the NetworkGameInfo.
* @param config the GRF to handle * @param config the GRF to handle
*/ */
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); } virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) = 0;
public: public:
/** On destructing of this class, the socket needs to be closed */
virtual ~NetworkUDPSocketHandler() { this->Close(); } virtual ~NetworkUDPSocketHandler() { this->Close(); }
bool Listen(uint32 host, uint16 port, bool broadcast); bool Listen(uint32 host, uint16 port, bool broadcast);