00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __NETWORK__H
00012 #define __NETWORK__H
00013
00014 #include "nxwcommn.h"
00015 #include "version.h"
00016 #include <iostream>
00017 #include "debug.h"
00018
00019 class ClientCrypt;
00020 using namespace std ;
00021
00022 #if defined(__unix__)
00023 #include <unistd.h>
00024 #include <sys/ioctl.h>
00025 #include <sys/socket.h>
00026 #include <netinet/in.h>
00027 #include <sys/signal.h>
00028 #include <sys/errno.h>
00029 #include <arpa/inet.h>
00030
00031 #define closesocket(s) close(s)
00032 #define ioctlsocket ioctl
00033 #else
00034 typedef int FAR socklen_t ;
00035 #endif
00036
00037 #include "srvparms.h"
00038
00039 #ifdef _WINDOWS
00040 #include "nxwgui.h"
00041 #endif
00042
00043
00044 #define IPPRINTF(I) ((I)&(0xFF)),((I>>8)&(0xFF)),((I>>16)&(0xFF)),(I>>24)
00045
00046 #define MTMAXBUFFER 65536
00047
00048 typedef struct
00049 {
00050 unsigned long address;
00051 unsigned long mask;
00052 }ip_block_st;
00053
00054 class NetThread
00055 {
00056 public:
00057 char outbuffer[MTMAXBUFFER];
00058 tthreads::Atomic<int> outhead;
00059 tthreads::Atomic<int> outtail;
00060 bool lastopwasinsert;
00061 tthreads::Mutex mtxrun;
00062 int realsocket;
00063 void run();
00064 void enqueue (char*, int);
00065 NetThread(int s);
00066 void set(int s);
00067 };
00068
00069 enum {
00070 T2A = 0x0001,
00071 LBR = 0x0002
00072 };
00073
00074
00075 class cNetwork
00076 {
00077 public:
00078 cNetwork();
00079
00080 void enterchar(int s);
00081 void startchar(int s);
00082 void LoginMain(int s);
00083 void xSend(NXWSOCKET socket, const void *point, int length );
00084 void xSend(NXWSOCKET socket, wstring& p, bool alsoTermination = true );
00085 void Disconnect(NXWSOCKET s);
00086 void ClearBuffers();
00087 void CheckConn();
00088 void CheckMessage();
00089 void SockClose();
00090 void FlushBuffer(NXWSOCKET s);
00091 void LoadHosts_deny( void );
00092 bool CheckForBlockedIP(sockaddr_in ip_address);
00093
00094 int kr,faul;
00095
00096 private:
00097
00098 std::vector<ip_block_st> hosts_deny;
00099
00100 void DoStreamCode(NXWSOCKET s);
00101 int Pack(void *pvIn, void *pvOut, int len);
00102 void Login2(int s);
00103 void Relay(int s);
00104 void GoodAuth(int s);
00105 void charplay (int s);
00106 void CharList(int s);
00107 int Receive(int s, int x, int a);
00108 void GetMsg(int s);
00109 char LogOut(NXWSOCKET s);
00110 void pSplit(char *pass0);
00111 void sockInit();
00112 void ActivateFeatures(NXWSOCKET s);
00113 unsigned char calculateLoginKey(unsigned char loginKey [4], unsigned char packetId );
00114 };
00115
00116 extern class cNetwork *Network;
00117
00118 NXWCLIENT getClientFromSocket(int s);
00119
00120 #endif