상속: NetworkClient
        ///////////////////////////////////////////
        public GameNetworkClient( bool entitySystemServiceEnabled )
        {
            if( instance != null )
                Log.Fatal( "GameNetworkClient.GameNetworkClient: instance != null." );
            instance = this;

            //register network services

            //register user management service
            userManagementService = new UserManagementClientNetworkService();
            RegisterService( userManagementService );

            //register custom messages service
            customMessagesService = new CustomMessagesClientNetworkService();
            RegisterService( customMessagesService );

            //register chat service
            chatService = new ChatClientNetworkService( userManagementService );
            RegisterService( chatService );

            //register entity system service
            if( entitySystemServiceEnabled )
            {
                entitySystemService = new EntitySystemClientNetworkService( userManagementService );
                RegisterService( entitySystemService );
            }
        }
예제 #2
0
        public void TryConnectToServer( string host, int port, string userName, string password )
        {
            GameNetworkClient client = new GameNetworkClient( true );

            client.ConnectionStatusChanged += Client_ConnectionStatusChanged;
            client.ChatService.ReceiveText += Client_ChatService_ReceiveText;
            client.CustomMessagesService.ReceiveMessage += Client_CustomMessagesService_ReceiveMessage;

            //add handlers for entity system service events
            client.EntitySystemService.WorldCreateBegin += Client_EntitySystemService_WorldCreateBegin;
            client.EntitySystemService.WorldCreateEnd += Client_EntitySystemService_WorldCreateEnd;
            client.EntitySystemService.WorldDestroy += Client_EntitySystemService_WorldDestroy;

            if( !client_SubscribedToMapLoadingEvents )
            {
                Map.Client_MapLoadingBegin += Map_Client_MapLoadingBegin;
                Map.Client_MapLoadingEnd += Map_Client_MapLoadingEnd;
                client_SubscribedToMapLoadingEvents = true;
            }

            string error;
            if( !client.BeginConnect( host, port, EngineVersionInformation.Version, userName, password,
                out error ) )
            {
                Log.Error( error );
                Client_DisconnectFromServer();
                return;
            }
        }
        public override void Dispose()
        {
            base.Dispose();

            instance = null;
        }
        void Connect_Click( EButton sender )
        {
            if( string.IsNullOrEmpty( userName ) )
            {
                SetInfo( "Invalid user name.", true );
                return;
            }

            SetInfo( "Connecting to the server...", false );

            GameNetworkClient client = new GameNetworkClient( true );
            client.ConnectionStatusChanged += Client_ConnectionStatusChanged;

            int port = 56565;
            string password = "";

            string error;
            if( !client.BeginConnect( connectToAddress, port, EngineVersionInformation.Version,
                userName, password, out error ) )
            {
                Log.Error( error );
                DisposeClient();
                return;
            }

            editBoxUserName.Enable = false;
            editBoxConnectTo.Enable = false;
            buttonCreateServer.Enable = false;
            buttonConnect.Enable = false;
        }
예제 #5
0
        void Connect()
        {
            if( GameNetworkClient.Instance != null )
            {
                Log( "Error: Client already connected" );
                return;
            }

            string loginName = textBoxUserName.Text.Trim();
            if( string.IsNullOrEmpty( loginName ) )
            {
                Log( "Error: Empty login name" );
                return;
            }

            GameNetworkClient client = new GameNetworkClient( false );
            client.ConnectionStatusChanged += Client_ConnectionStatusChanged;
            client.UserManagementService.AddUserEvent += UserManagementService_AddUserEvent;
            client.UserManagementService.RemoveUserEvent += UserManagementService_RemoveUserEvent;
            client.ChatService.ReceiveText += ChatService_ReceiveText;

            string password = "";

            int port = 56565;

            string error;
            if( !client.BeginConnect( textBoxAddress.Text, port, EngineVersionInformation.Version,
                loginName, password, out error ) )
            {
                Log( "Error: " + error );
                Disconnect();
                return;
            }

            buttonConnect.Enabled = false;
            buttonDisconnect.Enabled = true;
            textBoxUserName.ReadOnly = true;
            textBoxAddress.ReadOnly = true;
            textBoxEnterText.ReadOnly = true;
            buttonSend.Enabled = true;

            Log( "Trying to connect..." );
        }
예제 #6
0
        public override void Dispose()
        {
            base.Dispose();

            instance = null;
        }