Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------------------------------
- // NETWORK CLASS
- //--------------------------------------------------------------------------------------
- #define MSG_AUTHORIZE 2 // From server to client. The answer to the authorization
- #define MSG_INFOPLAYER 7 // From server to client. Information about player.
- #define MSG_INFOPLAYERS 8 // From server to client. Information about players. Message size depends on the number of players
- #define MSG_REGISTRATE 11 // From server to client. The answer to the registration
- #define MSG_CHATSER 16 // From client to server. Chat message
- #define MSG_CHAT 17 // From server to client. Chat message
- #define MSG_CHAT_VALID 18 // From server to client. Chat message valid with server time
- #define MSG_CHATBLOCK 19 // From server to client. Chat messages. Message size depends on the number of chat messages
- class CNet
- {
- public:
- //CNet() {} // Constructor
- //~CNet() {} // Destructor
- void(*setVersion)(WORD nVersion); // Set the version for comparison versions of client and server (by default it's 43, the engine version 0.43b)
- UINT(*startHost)(WORD port, WORD maxPlayers); // Start Host (port number, maximum clients/players)
- UINT(*startServer)(WORD port); // Start MMO Server
- void(*stopConnect)(); // Stop connect to the Server/Host
- 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)
- LPCWSTR(*getIP)(UINT iIP); // Return IP-address
- void(*connectToHost)(LPCWSTR ip, WORD port, LPCWSTR name); // Connect to the Host
- void(*connectToServer)(LPCWSTR ip, WORD port, LPCWSTR name, LPCWSTR pass); // Connect to the Server
- UINT(*getNID)(); // Get Network ID
- UINT(*getNIDServer)(); // Get Network ID of Server
- void(*msg)(UINT nid, BYTE* msg, DWORD size); // Network message (nid = 0 - to all with loop back)
- void(*msgToAll)(BYTE* msg, DWORD size); // Network message to all (no loop back)
- void(*guestContent)(bool bAllow); // Set flag to allow guest connections
- // Functions for the protocol to work with accounts and chat
- 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
- void(*setAccountAndChat)(); // Set work with account and chat on the client (only protocol)
- void(*sendRegistrToServer)(LPCWSTR sName, LPCWSTR sPass, LPCWSTR sMail, LPCWSTR sSkype, LPCWSTR sCountry, LPCWSTR sCity, BYTE nAgeSex, LPCWSTR sMyself); // Send registration to the server
- void(*sendChatMsgToServer)(UINT accRecipient, LPCWSTR sMsg); // Send chat message from the client to the server
- __time32_t(*sendChatMsgToClient)(UINT accRecipient, LPCWSTR sMsg); // Send chat message from the server to the client
- void(*sendGetContentToServer)(UINT param); // Send a request to download content
- void(*sendGetUpdateToServer)(WORD version, UINT param, bool x64); // Send a request to download update
- // Functions for transfer content
- // The requirement to the content: the size of each file should not exceed 4 GB
- // 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).
- // Should not contain exit to an external folder \.\ or \..\
- void(*setContentFolderAndFile)(LPCWSTR sFolder, LPCWSTR sFile); // Set content folder and file
- bool(*setMinMaxThreads)(BYTE nThreadMin, BYTE nThreadMax); // Set the minimum and maximum of threads for downloading content, return the flag of the true installation
- UINT(*addFile)(LPCWSTR sFile, UINT param); // Add file to list of content for distribution // Specify a file only within the directory (no "..")
- void(*prepareToSendContent)(); // Add work with content on the server, prepare to send content
- void(*prepareToReceiveContent)(); // Add work with content on the client, prepare to receive content
- //UINT(*addFileUpdate)(LPCWSTR sFile); // exe and NetWars.dll don't need added (only for server)
- //void(*prepareToSendUpdate)(WORD version); // Add work with update on the server, prepare to send update files (only for server)
- //setPathEngine(); // Set the path to DLL libraries of engine
- void setHModule(HMODULE hLib) // Set NetWars.dll
- {
- m_hLib = hLib;
- (FARPROC &)setVersion = GetProcAddress(hLib, "setVersion"); // Set the version for comparison versions of client and server
- (FARPROC &)startHost = GetProcAddress(hLib, "startHost"); // Start Host
- (FARPROC &)startServer = GetProcAddress(hLib, "startServer"); // Start MMO Server
- (FARPROC &)stopConnect = GetProcAddress(hLib, "stopConnect"); // Stop connect to the Server/Host
- (FARPROC &)setLoginAlways = GetProcAddress(hLib, "setLoginAlways"); // Flag of always login on the server
- (FARPROC &)getIP = GetProcAddress(hLib, "getIP"); // Return IP-address
- (FARPROC &)connectToHost = GetProcAddress(hLib, "connectToHost"); // Connect to the Host
- (FARPROC &)connectToServer = GetProcAddress(hLib, "connectToServer"); // Connect to the Server
- (FARPROC &)getNID = GetProcAddress(hLib, "getNID"); // Get Network ID
- (FARPROC &)getNIDServer = GetProcAddress(hLib, "getNIDServer"); // Get Network ID of Server
- (FARPROC &)msg = GetProcAddress(hLib, "msg"); // Network message (nid=0 - to all with loop back)
- (FARPROC &)msgToAll = GetProcAddress(hLib, "msgToAll"); // Network message to all (no loop back)
- (FARPROC &)guestContent = GetProcAddress(hLib, "guestContent"); // Set flag to allow guest connections
- // Functions for the protocol to work with accounts and chat
- (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
- (FARPROC &)setAccountAndChat = GetProcAddress(hLib, "setAccountAndChat"); // Set work with account and chat on the client
- (FARPROC &)sendRegistrToServer = GetProcAddress(hLib, "sendRegistrToServer"); // Send registration to the server
- (FARPROC &)sendChatMsgToServer = GetProcAddress(hLib, "sendChatMsgToServer"); // Send chat message from the client to the server
- (FARPROC &)sendChatMsgToClient = GetProcAddress(hLib, "sendChatMsgToClient"); // Send chat message from the server to the client
- (FARPROC &)sendGetContentToServer = GetProcAddress(hLib, "sendGetContentToServer"); // Send a request to download content
- // Functions for transfer content
- (FARPROC &)setContentFolderAndFile = GetProcAddress(hLib, "setContentFolderAndFile"); // Set content folder and file
- (FARPROC &)setContentFolderAndFile = GetProcAddress(hLib, "setMinMaxThreads"); // Set the minimum and maximum of threads for downloading content, return the flag of the true installation
- (FARPROC &)addFile = GetProcAddress(hLib, "addFileContent"); // Add file to list of content for distribution
- (FARPROC &)prepareToSendContent = GetProcAddress(hLib, "prepareToSendContent"); // Add work with content on the server, prepare to send content
- (FARPROC &)prepareToReceiveContent = GetProcAddress(hLib, "prepareToReceiveContent"); // Add work with content on the client, prepare to receive content
- //(FARPROC &)addFileUpdate = GetProcAddress(hLib, "addFileUpdate"); // Add file to list of content for distribution
- }
- // Set callback function for connect the player to the server (host) or connect the server (host) to the player
- void setCallbackConnect()
- {
- void(*pConnect)(LPCALLBACKCONNECTPLAYER pCallback);
- (FARPROC &)pConnect = GetProcAddress(m_hLib, "SetCallbackConnectPlayer");
- pConnect(onConnect);
- }
- // Set callback function for disconnect the player from the server (host) or disconnect the server (host) from the player
- void setCallbackDisconnect()
- {
- void(*pDisconnect)(LPCALLBACKDISCONNECTPLAYER pCallback);
- (FARPROC &)pDisconnect = GetProcAddress(m_hLib, "SetCallbackDisconnectPlayer");
- pDisconnect(onDisconnect);
- }
- // Set callback function for get the network message
- void setCallbackNetMsg()
- {
- void(*pNetMsg)(LPCALLBACKNETMSG pCallback);
- (FARPROC &)pNetMsg = GetProcAddress(m_hLib, "SetCallbackNetMsg");
- pNetMsg(onNetMsg);
- }
- protected:
- HMODULE m_hLib; // NetWars.dll
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement