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