OpenTTD
core.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
14 #include "../../stdafx.h"
15 #include "../../debug.h"
16 #include "os_abstraction.h"
17 #include "packet.h"
18 
19 #include "../../safeguards.h"
20 
21 
27 {
28 /* Let's load the network in windows */
29 #ifdef _WIN32
30  {
31  WSADATA wsa;
32  DEBUG(net, 3, "[core] loading windows socket library");
33  if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
34  DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
35  return false;
36  }
37  }
38 #endif /* _WIN32 */
39 
40  return true;
41 }
42 
47 {
48 #if defined(_WIN32)
49  WSACleanup();
50 #endif
51 }
52 
53 
60 {
61  uint j;
62  p->Send_uint32(grf->grfid);
63  for (j = 0; j < sizeof(grf->md5sum); j++) {
64  p->Send_uint8 (grf->md5sum[j]);
65  }
66 }
67 
74 {
75  uint j;
76  grf->grfid = p->Recv_uint32();
77  for (j = 0; j < sizeof(grf->md5sum); j++) {
78  grf->md5sum[j] = p->Recv_uint8();
79  }
80 }
Internal entity of a packet.
Definition: packet.h:42
Network stuff has many things that needs to be included and/or implemented by default.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Definition: packet.cpp:248
bool NetworkCoreInitialize()
Initializes the network core (as that is needed for some platforms.
Definition: core.cpp:26
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
Definition: packet.cpp:98
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
Definition: packet.cpp:119
Basic data to distinguish a GRF.
Definition: newgrf_config.h:84
void NetworkCoreShutdown()
Shuts down the network core (as that is needed for some platforms.
Definition: core.cpp:46
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:37
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
Definition: packet.cpp:219
Basic functions to create, fill and read packets.
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:85
void ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Definition: core.cpp:73
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:86
void SendGRFIdentifier(Packet *p, const GRFIdentifier *grf)
Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
Definition: core.cpp:59