core.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00014 #ifdef ENABLE_NETWORK
00015
00016 #include "../../stdafx.h"
00017 #include "../../debug.h"
00018 #include "os_abstraction.h"
00019 #include "packet.h"
00020
00021
00022 #ifdef __MORPHOS__
00023
00024 struct Library *SocketBase = NULL;
00025 #endif
00026
00031 bool NetworkCoreInitialize()
00032 {
00033 #if defined(__MORPHOS__) || defined(__AMIGA__)
00034
00035
00036
00037
00038 DEBUG(net, 3, "[core] loading bsd socket library");
00039 SocketBase = OpenLibrary("bsdsocket.library", 4);
00040 if (SocketBase == NULL) {
00041 DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable");
00042 return false;
00043 }
00044
00045 #if defined(__AMIGA__)
00046
00047 TimerPort = CreateMsgPort();
00048 if (TimerPort != NULL) {
00049 TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest);
00050 if (TimerRequest != NULL) {
00051 if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) {
00052 TimerBase = TimerRequest->tr_node.io_Device;
00053 if (TimerBase == NULL) {
00054
00055 DEBUG(net, 0, "[core] can't initialize timer, network unavailable");
00056 return false;
00057 }
00058 }
00059 }
00060 }
00061 #endif
00062 #endif
00063
00064
00065 #ifdef WIN32
00066 {
00067 WSADATA wsa;
00068 DEBUG(net, 3, "[core] loading windows socket library");
00069 if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
00070 DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
00071 return false;
00072 }
00073 }
00074 #endif
00075
00076 return true;
00077 }
00078
00082 void NetworkCoreShutdown()
00083 {
00084 #if defined(__MORPHOS__) || defined(__AMIGA__)
00085
00086 #if defined(__AMIGA__)
00087 if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest);
00088 if (TimerRequest != NULL) DeleteIORequest(TimerRequest);
00089 if (TimerPort != NULL) DeleteMsgPort(TimerPort);
00090 #endif
00091
00092 if (SocketBase != NULL) CloseLibrary(SocketBase);
00093 #endif
00094
00095 #if defined(WIN32)
00096 WSACleanup();
00097 #endif
00098 }
00099
00100
00106 void NetworkSocketHandler::SendGRFIdentifier(Packet *p, const GRFIdentifier *grf)
00107 {
00108 uint j;
00109 p->Send_uint32(grf->grfid);
00110 for (j = 0; j < sizeof(grf->md5sum); j++) {
00111 p->Send_uint8 (grf->md5sum[j]);
00112 }
00113 }
00114
00120 void NetworkSocketHandler::ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
00121 {
00122 uint j;
00123 grf->grfid = p->Recv_uint32();
00124 for (j = 0; j < sizeof(grf->md5sum); j++) {
00125 grf->md5sum[j] = p->Recv_uint8();
00126 }
00127 }
00128
00129 #endif