Advertisement
Guest User

netwars-govnoengine-03

a guest
Jun 2nd, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.29 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------
  2. // NETWORK CLASS
  3. //--------------------------------------------------------------------------------------
  4. #define MSG_AUTHORIZE   2   // From server to client. The answer to the authorization
  5. #define MSG_INFOPLAYER  7   // From server to client. Information about player.
  6. #define MSG_INFOPLAYERS 8   // From server to client. Information about players. Message size depends on the number of players
  7. #define MSG_REGISTRATE  11  // From server to client. The answer to the registration
  8. #define MSG_CHATSER     16  // From client to server. Chat message
  9. #define MSG_CHAT        17  // From server to client. Chat message
  10. #define MSG_CHAT_VALID  18  // From server to client. Chat message valid with server time
  11. #define MSG_CHATBLOCK   19  // From server to client. Chat messages. Message size depends on the number of chat messages
  12.  
  13.  
  14. class CNet
  15. {
  16. public:
  17.     //CNet()    {}  // Constructor
  18.     //~CNet()   {}  // Destructor
  19.  
  20.     void(*setVersion)(WORD nVersion);   // Set the version for comparison versions of client and server (by default it's 43, the engine version 0.43b)
  21.     UINT(*startHost)(WORD port, WORD maxPlayers);   // Start Host (port number, maximum clients/players)
  22.     UINT(*startServer)(WORD port);  // Start MMO Server
  23.     void(*stopConnect)();   // Stop connect to the Server/Host
  24.     void(*setLoginAlways)(bool bLoginAlways);   // Flag of always login on the server (even if the incorrect version or if any invalid login is automatically created new player with the name of Player"ID", ID - from 1)
  25.     LPCWSTR(*getIP)(UINT iIP);  // Return IP-address
  26.     void(*connectToHost)(LPCWSTR ip, WORD port, LPCWSTR name);  // Connect to the Host
  27.     void(*connectToServer)(LPCWSTR ip, WORD port, LPCWSTR name, LPCWSTR pass);  // Connect to the Server
  28.     UINT(*getNID)();    // Get Network ID
  29.     UINT(*getNIDServer)();  // Get Network ID of Server
  30.     void(*msg)(UINT nid, BYTE* msg, DWORD size);    // Network message (nid = 0 - to all with loop back)
  31.     void(*msgToAll)(BYTE* msg, DWORD size); // Network message to all (no loop back)
  32.  
  33.     void(*guestContent)(bool bAllow);   // Set flag to allow guest connections
  34.  
  35.     // Functions for the protocol to work with accounts and chat
  36.     UINT(*addAccountAndChat)(LPCWSTR sName, LPCWSTR sServer, LPCWSTR sLogin, LPCWSTR sPassword);    // Add work with account and chat on the server (DB tables and protocol), Connect to SQL Server (with Accounts and Chat), Activate the server database, Return number of accounts in the DataBase
  37.     void(*setAccountAndChat)(); // Set work with account and chat on the client (only protocol)
  38.     void(*sendRegistrToServer)(LPCWSTR sName, LPCWSTR sPass, LPCWSTR sMail, LPCWSTR sSkype, LPCWSTR sCountry, LPCWSTR sCity, BYTE nAgeSex, LPCWSTR sMyself);    // Send registration to the server
  39.     void(*sendChatMsgToServer)(UINT accRecipient, LPCWSTR sMsg);    // Send chat message from the client to the server
  40.     __time32_t(*sendChatMsgToClient)(UINT accRecipient, LPCWSTR sMsg);  // Send chat message from the server to the client
  41.     void(*sendGetContentToServer)(UINT param);  // Send a request to download content
  42.     void(*sendGetUpdateToServer)(WORD version, UINT param, bool x64);   // Send a request to download update
  43.  
  44.     // Functions for transfer content
  45.     // The requirement to the content: the size of each file should not exceed 4 GB
  46.     // Do not forget to take into account that the maximum length of the path and file name can not be more than MAXPATH (260 or 256).
  47.     // Should not contain exit to an external folder \.\ or \..\
  48.     void(*setContentFolderAndFile)(LPCWSTR sFolder, LPCWSTR sFile); // Set content folder and file
  49.     bool(*setMinMaxThreads)(BYTE nThreadMin, BYTE nThreadMax);  // Set the minimum and maximum of threads for downloading content, return the flag of the true installation
  50.     UINT(*addFile)(LPCWSTR sFile, UINT param);  // Add file to list of content for distribution // Specify a file only within the directory (no "..")
  51.     void(*prepareToSendContent)();  // Add work with content on the server, prepare to send content
  52.     void(*prepareToReceiveContent)();   // Add work with content on the client, prepare to receive content
  53.  
  54.     //UINT(*addFileUpdate)(LPCWSTR sFile);  // exe and NetWars.dll don't need added (only for server)
  55.     //void(*prepareToSendUpdate)(WORD version); // Add work with update on the server, prepare to send update files (only for server)
  56.  
  57.     //setPathEngine();  // Set the path to DLL libraries of engine
  58.  
  59.     void setHModule(HMODULE hLib)   // Set NetWars.dll
  60.     {
  61.         m_hLib = hLib;
  62.  
  63.         (FARPROC &)setVersion = GetProcAddress(hLib, "setVersion"); // Set the version for comparison versions of client and server
  64.         (FARPROC &)startHost = GetProcAddress(hLib, "startHost");   // Start Host
  65.         (FARPROC &)startServer = GetProcAddress(hLib, "startServer");   // Start MMO Server
  66.         (FARPROC &)stopConnect = GetProcAddress(hLib, "stopConnect");   // Stop connect to the Server/Host
  67.         (FARPROC &)setLoginAlways = GetProcAddress(hLib, "setLoginAlways"); // Flag of always login on the server
  68.         (FARPROC &)getIP = GetProcAddress(hLib, "getIP");   // Return IP-address
  69.         (FARPROC &)connectToHost = GetProcAddress(hLib, "connectToHost");   // Connect to the Host
  70.         (FARPROC &)connectToServer = GetProcAddress(hLib, "connectToServer");   // Connect to the Server
  71.         (FARPROC &)getNID = GetProcAddress(hLib, "getNID"); // Get Network ID
  72.         (FARPROC &)getNIDServer = GetProcAddress(hLib, "getNIDServer"); // Get Network ID of Server
  73.         (FARPROC &)msg = GetProcAddress(hLib, "msg");   // Network message (nid=0 - to all with loop back)
  74.         (FARPROC &)msgToAll = GetProcAddress(hLib, "msgToAll"); // Network message to all (no loop back)
  75.         (FARPROC &)guestContent = GetProcAddress(hLib, "guestContent"); // Set flag to allow guest connections
  76.  
  77.         // Functions for the protocol to work with accounts and chat
  78.         (FARPROC &)addAccountAndChat = GetProcAddress(hLib, "addAccountAndChatEx"); // Add work with account and chat on the server, Connect to SQL Server, Activate the server database, Return number of accounts in the DataBase
  79.         (FARPROC &)setAccountAndChat = GetProcAddress(hLib, "setAccountAndChat");   // Set work with account and chat on the client
  80.         (FARPROC &)sendRegistrToServer = GetProcAddress(hLib, "sendRegistrToServer");   // Send registration to the server
  81.         (FARPROC &)sendChatMsgToServer = GetProcAddress(hLib, "sendChatMsgToServer");   // Send chat message from the client to the server
  82.         (FARPROC &)sendChatMsgToClient = GetProcAddress(hLib, "sendChatMsgToClient");   // Send chat message from the server to the client
  83.         (FARPROC &)sendGetContentToServer = GetProcAddress(hLib, "sendGetContentToServer"); // Send a request to download content
  84.  
  85.         // Functions for transfer content
  86.         (FARPROC &)setContentFolderAndFile = GetProcAddress(hLib, "setContentFolderAndFile");   // Set content folder and file
  87.         (FARPROC &)setContentFolderAndFile = GetProcAddress(hLib, "setMinMaxThreads");  // Set the minimum and maximum of threads for downloading content, return the flag of the true installation
  88.         (FARPROC &)addFile = GetProcAddress(hLib, "addFileContent");    // Add file to list of content for distribution
  89.         (FARPROC &)prepareToSendContent = GetProcAddress(hLib, "prepareToSendContent"); // Add work with content on the server, prepare to send content
  90.         (FARPROC &)prepareToReceiveContent = GetProcAddress(hLib, "prepareToReceiveContent");   // Add work with content on the client, prepare to receive content
  91.  
  92.         //(FARPROC &)addFileUpdate = GetProcAddress(hLib, "addFileUpdate"); // Add file to list of content for distribution
  93.     }
  94.  
  95.     // Set callback function for connect the player to the server (host) or connect the server (host) to the player
  96.     void setCallbackConnect()
  97.     {
  98.         void(*pConnect)(LPCALLBACKCONNECTPLAYER pCallback);
  99.         (FARPROC &)pConnect = GetProcAddress(m_hLib, "SetCallbackConnectPlayer");
  100.         pConnect(onConnect);
  101.     }
  102.  
  103.     // Set callback function for disconnect the player from the server (host) or disconnect the server (host) from the player
  104.     void setCallbackDisconnect()
  105.     {
  106.         void(*pDisconnect)(LPCALLBACKDISCONNECTPLAYER pCallback);
  107.         (FARPROC &)pDisconnect = GetProcAddress(m_hLib, "SetCallbackDisconnectPlayer");
  108.         pDisconnect(onDisconnect);
  109.     }
  110.  
  111.     // Set callback function for get the network message
  112.     void setCallbackNetMsg()
  113.     {
  114.         void(*pNetMsg)(LPCALLBACKNETMSG pCallback);
  115.         (FARPROC &)pNetMsg = GetProcAddress(m_hLib, "SetCallbackNetMsg");
  116.         pNetMsg(onNetMsg);
  117.     }
  118.  
  119. protected:
  120.  
  121.     HMODULE m_hLib; // NetWars.dll
  122. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement