Clone of UAS2 @ https://github.com/drudgedance/uas2

WorldServer.h 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file WorldServer.h
  19. */
  20. #ifndef __WORLDSERVER_H
  21. #define __WORLDSERVER_H
  22. #include "uas.h"
  23. class cWorldServer
  24. {
  25. friend class cMasterServer;
  26. public:
  27. static void Initialize( short nPort, WORD wLogicalID, DWORD dwSendCRCSeed, DWORD dwRecvCRCSeed )
  28. {
  29. UpdateConsole( " Starting World Server ... " );
  30. SOCKADDR_IN saSockAddr;
  31. saSockAddr.sin_family = AF_INET;
  32. saSockAddr.sin_port = htons( nPort );
  33. saSockAddr.sin_addr.s_addr = INADDR_ANY;
  34. m_wLogicalID = wLogicalID;
  35. m_dwSendCRCSeed = dwSendCRCSeed;
  36. m_dwRecvCRCSeed = dwRecvCRCSeed;
  37. m_Socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
  38. if ( !m_Socket )
  39. {
  40. UpdateConsole( "socket( ) failed!\r\n" );
  41. return ;
  42. }
  43. if ( bind( m_Socket, (struct sockaddr *)&saSockAddr, sizeof( SOCKADDR_IN ) ) )
  44. {
  45. UpdateConsole( "bind( ) failed!\r\n" );
  46. return ;
  47. }
  48. UpdateConsole( "success.\r\n" );
  49. }
  50. static void Halt( )
  51. {
  52. closesocket( m_Socket );
  53. UpdateConsole( " World Server: closing socket ...\r\n" );
  54. }
  55. protected:
  56. static DWORD m_dwSendCRCSeed;
  57. static DWORD m_dwRecvCRCSeed;
  58. static WORD m_wLogicalID;
  59. static SOCKET m_Socket;
  60. };
  61. #endif // #ifndef __WORLDSERVER_H