OpenTTD Source: src/network/core/core.cpp Source File

OpenTTD Source 1.11.0-RC1

core.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
12 #include "../../stdafx.h"
13 #include "../../debug.h"
14 #include "os_abstraction.h"
15 #include "packet.h"
16
17 #include "../../safeguards.h"
18
19
24 bool NetworkCoreInitialize()
25 {
26 /* Let's load the network in windows */
27 #ifdef _WIN32
28 {
29 WSADATA wsa;
30 DEBUG(net, 3, "[core] loading windows socket library");
31 if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
32 DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
33 return false;
34 }
35 }
36 #endif /* _WIN32 */
37
38 return true;
39 }
40
44 void NetworkCoreShutdown()
45 {
46 #if defined(_WIN32)
47 WSACleanup();
48 #endif
49 }
50
51
57 void NetworkSocketHandler::SendGRFIdentifier(Packet *p, const GRFIdentifier *grf)
58 {
59 uint j;
60 p->Send_uint32(grf->grfid);
61 for (j = 0; j < sizeof(grf->md5sum); j++) {
62 p->Send_uint8 (grf->md5sum[j]);
63 }
64 }
65
71 void NetworkSocketHandler::ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
72 {
73 uint j;
74 grf->grfid = p->Recv_uint32();
75 for (j = 0; j < sizeof(grf->md5sum); j++) {
76 grf->md5sum[j] = p->Recv_uint8();
77 }
78 }
Packet::Send_uint8
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Definition: packet.cpp:96
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
Packet::Send_uint32
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
Definition: packet.cpp:117
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
Packet::Recv_uint32
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:246
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
NetworkSocketHandler::SendGRFIdentifier
void SendGRFIdentifier(Packet *p, const GRFIdentifier *grf)
Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
Definition: core.cpp:57
Packet
Internal entity of a packet.
Definition: packet.h:40
NetworkCoreShutdown
void NetworkCoreShutdown()
Shuts down the network core (as that is needed for some platforms.
Definition: core.cpp:44
packet.h
Packet::Recv_uint8
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:217
NetworkSocketHandler::ReceiveGRFIdentifier
void ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Definition: core.cpp:71
os_abstraction.h
NetworkCoreInitialize
bool NetworkCoreInitialize()
Initializes the network core (as that is needed for some platforms.
Definition: core.cpp:24