- Main Page
- Classes
- Files

- File List
- File Members

# E:/uas2/Server/WorldServer.h

Go to the documentation of this file.

    00001 /*
    00002 * This file is part of UAS2.
    00003 *
    00004 * UAS2 is free software; you can redistribute it and/or modify
    00005 * it under the terms of the GNU General Public License as published by
    00006 * the Free Software Foundation; either version 2 of the License, or
    00007 * (at your option) any later version.
    00008 *
    00009 * UAS2 is distributed in the hope that it will be useful,
    00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012 * GNU General Public License for more details.
    00013
    00014 * You should have received a copy of the GNU General Public License
    00015 * along with UASv1; if not, write to the Free Software
    00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00017 */
    00018
    00023 #ifndef __WORLDSERVER_H
    00024 #define __WORLDSERVER_H
    00025
    00026 #include "uas.h"
    00027
    00028 class cWorldServer
    00029 {
    00030         friend class cMasterServer;
    00031
    00032 public:
    00033
    00034         static void Initialize( short nPort, WORD wLogicalID, DWORD dwSendCRCSeed, DWORD dwRecvCRCSeed )
    00035         {
    00036                 UpdateConsole( " Starting World Server ... " );
    00037
    00038                 SOCKADDR_IN     saSockAddr;
    00039                 saSockAddr.sin_family           = AF_INET;
    00040                 saSockAddr.sin_port                     = htons( nPort );
    00041                 saSockAddr.sin_addr.s_addr      = INADDR_ANY;
    00042
    00043                 m_wLogicalID    = wLogicalID;
    00044                 m_dwSendCRCSeed = dwSendCRCSeed;
    00045                 m_dwRecvCRCSeed = dwRecvCRCSeed;
    00046
    00047                 m_Socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
    00048                 if ( !m_Socket )
    00049                 {
    00050                         UpdateConsole( "socket( ) failed!\r\n" );
    00051                         return ;
    00052                 }
    00053
    00054                 if ( bind( m_Socket, (struct sockaddr *)&saSockAddr, sizeof( SOCKADDR_IN ) ) )
    00055                 {
    00056                         UpdateConsole( "bind( ) failed!\r\n" );
    00057                         return ;
    00058                 }
    00059
    00060                 UpdateConsole( "success.\r\n" );
    00061         }
    00062
    00063         static void Halt( )
    00064         {
    00065                 closesocket( m_Socket );
    00066                 UpdateConsole( " World Server: closing socket ...\r\n" );
    00067         }
    00068
    00069 protected:
    00070         static DWORD            m_dwSendCRCSeed;
    00071         static DWORD            m_dwRecvCRCSeed;
    00072         static WORD                     m_wLogicalID;
    00073         static SOCKET           m_Socket;
    00074 };
    00075
    00076 #endif  // #ifndef __WORLDSERVER_H