core.cpp
Go to the documentation of this file.00001
00002
00007 #ifdef ENABLE_NETWORK
00008
00009 #include "../../stdafx.h"
00010 #include "../../debug.h"
00011 #include "os_abstraction.h"
00012 #include "core.h"
00013 #include "packet.h"
00014
00015
00016 #ifdef __MORPHOS__
00017
00018 struct Library *SocketBase = NULL;
00019 #endif
00020
00025 bool NetworkCoreInitialize()
00026 {
00027 #if defined(__MORPHOS__) || defined(__AMIGA__)
00028
00029
00030
00031
00032 DEBUG(net, 3, "[core] loading bsd socket library");
00033 SocketBase = OpenLibrary("bsdsocket.library", 4);
00034 if (SocketBase == NULL) {
00035 DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable");
00036 return false;
00037 }
00038
00039 #if defined(__AMIGA__)
00040
00041 TimerPort = CreateMsgPort();
00042 if (TimerPort != NULL) {
00043 TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest);
00044 if (TimerRequest != NULL) {
00045 if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) {
00046 TimerBase = TimerRequest->tr_node.io_Device;
00047 if (TimerBase == NULL) {
00048
00049 DEBUG(net, 0, "[core] can't initialize timer, network unavailable");
00050 return false;
00051 }
00052 }
00053 }
00054 }
00055 #endif
00056 #endif
00057
00058
00059 #ifdef WIN32
00060 {
00061 WSADATA wsa;
00062 DEBUG(net, 3, "[core] loading windows socket library");
00063 if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
00064 DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
00065 return false;
00066 }
00067 }
00068 #endif
00069
00070 return true;
00071 }
00072
00076 void NetworkCoreShutdown()
00077 {
00078 #if defined(__MORPHOS__) || defined(__AMIGA__)
00079
00080 #if defined(__AMIGA__)
00081 if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest);
00082 if (TimerRequest != NULL) DeleteIORequest(TimerRequest);
00083 if (TimerPort != NULL) DeleteMsgPort(TimerPort);
00084 #endif
00085
00086 if (SocketBase != NULL) CloseLibrary(SocketBase);
00087 #endif
00088
00089 #if defined(WIN32)
00090 WSACleanup();
00091 #endif
00092 }
00093
00094
00100 void NetworkSocketHandler::Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf)
00101 {
00102 uint j;
00103 p->Send_uint32(grf->grfid);
00104 for (j = 0; j < sizeof(grf->md5sum); j++) {
00105 p->Send_uint8 (grf->md5sum[j]);
00106 }
00107 }
00108
00114 void NetworkSocketHandler::Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf)
00115 {
00116 uint j;
00117 grf->grfid = p->Recv_uint32();
00118 for (j = 0; j < sizeof(grf->md5sum); j++) {
00119 grf->md5sum[j] = p->Recv_uint8();
00120 }
00121 }
00122
00123 #endif