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

CharacterServer.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 CharacterServer.h
  19. */
  20. #ifndef __CHARACTERSERVER_H
  21. #define __CHARACTERSERVER_H
  22. #include "uas.h"
  23. class cCharacterServer
  24. {
  25. friend class cMasterServer;
  26. public:
  27. static DWORD m_dwClientCount;
  28. static DWORD ReturnPadOffset( DWORD dwLength );
  29. static void Initialize( short nPort, WORD wLogicalID, DWORD dwSendCRCSeed, DWORD dwRecvCRCSeed )
  30. {
  31. UpdateConsole( "\r\n Starting Character Server ... " );
  32. SOCKADDR_IN saSockAddr;
  33. saSockAddr.sin_family = AF_INET;
  34. saSockAddr.sin_port = htons( nPort );
  35. saSockAddr.sin_addr.s_addr = INADDR_ANY;
  36. m_wLogicalID = wLogicalID;
  37. m_dwSendCRCSeed = dwSendCRCSeed;
  38. m_dwRecvCRCSeed = dwRecvCRCSeed;
  39. m_Socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
  40. if ( !m_Socket )
  41. {
  42. UpdateConsole( "socket( ) failed!\r\n" );
  43. return ;
  44. }
  45. if ( bind( m_Socket, (struct sockaddr *)&saSockAddr, sizeof( SOCKADDR_IN ) ) )
  46. {
  47. UpdateConsole( "bind( ) failed!\r\n" );
  48. return ;
  49. }
  50. UpdateConsole( "success.\r\n" );
  51. }
  52. static void Halt( )
  53. {
  54. closesocket( m_Socket );
  55. UpdateConsole( " Character Server: closing socket ...\r\n" );
  56. }
  57. protected:
  58. static DWORD m_dwSendCRCSeed;
  59. static DWORD m_dwRecvCRCSeed;
  60. static WORD m_wLogicalID;
  61. static SOCKET m_Socket;
  62. };
  63. #endif // #ifndef __CHARACTERSERVER_H