public void SayPrivate(string text, UserManagementServerNetworkService.UserInfo toUser)
 {
     UserManagementServerNetworkService.UserInfo fromUser = userManagementService.ServerUser;
     if (fromUser == null)
         Log.Fatal("ChatServerNetworkService: Say: Server user is not created.");
     SendText(fromUser, text, toUser);
 }
        //

        public GameNetworkServer(string serverName, string serverVersion, int maxConnections,
                                 bool entitySystemServiceEnabled)
            : base(serverName, serverVersion, maxConnections)
        {
            if (instance != null)
            {
                Log.Fatal("GameNetworkServer.GameNetworkServer: instance != null.");
            }
            instance = this;

            //register network services

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

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

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

            //register entity system service
            if (entitySystemServiceEnabled)
            {
                entitySystemService = new EntitySystemServerNetworkService(userManagementService);
                RegisterService(entitySystemService);
            }
        }
        //

		public GameNetworkServer( string serverName, string serverVersion, int maxConnections,
            bool entitySystemServiceEnabled)
            : base(serverName, serverVersion, maxConnections)
        {
            if (instance != null)
                Log.Fatal("GameNetworkServer.GameNetworkServer: instance != null.");
            instance = this;

            //register network services

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

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

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

            //register entity system service
            if (entitySystemServiceEnabled)
            {
                entitySystemService = new EntitySystemServerNetworkService(userManagementService);
                RegisterService(entitySystemService);
            }
        }
 private void UserManagementService_AddUserEvent(UserManagementServerNetworkService service,
                                                 UserManagementServerNetworkService.UserInfo user)
 {
     if (World.Instance != null && EntitySystemWorld.Instance.IsServer())
     {
         CreateClientRemoteEntityWorldAndSynchronizeWorld(user);
     }
 }
Пример #5
0
        void ChatService_ReceiveText( ChatServerNetworkService sender,
			UserManagementServerNetworkService.UserInfo fromUser,
			string text, UserManagementServerNetworkService.UserInfo privateToUser )
        {
            string userName = fromUser != null ? fromUser.Name : "(null)";
            string toUserName = privateToUser != null ? privateToUser.Name : "All";
            Log( "Chat: {0} -> {1}: {2}", userName, toUserName, text );
        }
        ///////////////////////////////////////////

        public ChatServerNetworkService(UserManagementServerNetworkService userManagementService)
            : base("Chat", 3)
        {
            this.userManagementService = userManagementService;

            //register message types
            RegisterMessageType("textToServer", 1, ReceiveMessage_TextToServer);
            RegisterMessageType("textToClient", 2);
        }
Пример #7
0
        ///////////////////////////////////////////

        public ChatServerNetworkService(UserManagementServerNetworkService userManagementService)
            : base("Chat", 3)
        {
            this.userManagementService = userManagementService;

            //register message types
            RegisterMessageType("textToServer", 1, ReceiveMessage_TextToServer);
            RegisterMessageType("textToClient", 2);
        }
        private void UserManagementService_RemoveUserEvent(UserManagementServerNetworkService service,
                                                           UserManagementServerNetworkService.UserInfo user)
        {
            ClientRemoteEntityWorld remoteEntityWorld = GetRemoteEntityWorld(user);

            if (remoteEntityWorld != null)
            {
                networkingInterface.DisconnectRemoteEntityWorld(remoteEntityWorld);
                clientRemoteEntityWorlds.Remove(remoteEntityWorld);
            }
        }
        ///////////////////////////////////////////

        public EntitySystemServerNetworkService(
            UserManagementServerNetworkService userManagementService)
            : base("EntitySystem", 4)
        {
            this.userManagementService = userManagementService;

            //register message types
            for (int n = 0; n < 6; n++)
            {
                entitySystemInternalMessageTypes[n] = RegisterMessageType(
                    string.Format("entitySystemInternal{0}", n), (byte)(n + 1),
                    ReceiveMessage_EntitySystemInternal);
            }
            RegisterMessageType("worldCreateBeginToClient", 7);
            RegisterMessageType("worldCreateEndToClient", 8);
            RegisterMessageType("worldDestroyToClient", 9);
            RegisterMessageType("worldIdentifierToServer", 10, ReceiveMessage_CheckWorldIdentifierToServer);

            networkingInterface = new ServerEntitySystemNetworkingInterface(this);

            userManagementService.AddUserEvent    += UserManagementService_AddUserEvent;
            userManagementService.RemoveUserEvent += UserManagementService_RemoveUserEvent;
        }
Пример #10
0
		void UserManagementService_AddUserEvent( UserManagementServerNetworkService sender,
			UserManagementServerNetworkService.UserInfo user )
		{
			Log( "User connected: " + user.ToString() );
			listBoxUsers.Items.Add( user );
		}
        ///////////////////////////////////////////

        public EntitySystemServerNetworkService(
            UserManagementServerNetworkService userManagementService)
            : base("EntitySystem", 4)
        {
            this.userManagementService = userManagementService;

            //register message types
            for (int n = 0; n < 6; n++)
            {
                entitySystemInternalMessageTypes[n] = RegisterMessageType(
                    string.Format("entitySystemInternal{0}", n), (byte)(n + 1),
                    ReceiveMessage_EntitySystemInternal);
            }
            RegisterMessageType("worldCreateBeginToClient", 7);
            RegisterMessageType("worldCreateEndToClient", 8);
            RegisterMessageType("worldDestroyToClient", 9);
            RegisterMessageType("worldIdentifierToServer", 10, ReceiveMessage_CheckWorldIdentifierToServer);

            networkingInterface = new ServerEntitySystemNetworkingInterface(this);

            userManagementService.AddUserEvent += UserManagementService_AddUserEvent;
            userManagementService.RemoveUserEvent += UserManagementService_RemoveUserEvent;
        }
            //

            internal ClientRemoteEntityWorld(UserManagementServerNetworkService.UserInfo user)
                : base("Client remote entity world (User: \"" + user.ToString() + "\")")
            {
                this.user = user;
            }
        private void CreateClientRemoteEntityWorldAndSynchronizeWorld(
            UserManagementServerNetworkService.UserInfo user)
        {
            if (user.ConnectedNode != null)//check for local user
            {
                {
                    MessageType messageType = GetMessageType("worldCreateBeginToClient");
                    SendDataWriter writer = BeginMessage(user.ConnectedNode, messageType);

                    writer.Write(World.Instance.Type.Name);

                    if (Map.Instance != null)
                        writer.Write(Map.Instance.VirtualFileName);
                    else
                        writer.Write("");

                    writer.Write(worldCheckIdentifier);

                    EndMessage();
                }

                if (GetRemoteEntityWorld(user) == null)//check for arealdy created
                {
                    //create entity remote world
                    ClientRemoteEntityWorld remoteEntityWorld = new ClientRemoteEntityWorld(user);
                    clientRemoteEntityWorlds.Add(remoteEntityWorld);
                    networkingInterface.ConnectRemoteEntityWorld(remoteEntityWorld);
                }

                {
                    MessageType messageType = GetMessageType("worldCreateEndToClient");
                    SendDataWriter writer = BeginMessage(user.ConnectedNode, messageType);
                    EndMessage();
                }
            }
        }
 private void UserManagementService_RemoveUserEvent(UserManagementServerNetworkService service,
     UserManagementServerNetworkService.UserInfo user)
 {
     ClientRemoteEntityWorld remoteEntityWorld = GetRemoteEntityWorld(user);
     if (remoteEntityWorld != null)
     {
         networkingInterface.DisconnectRemoteEntityWorld(remoteEntityWorld);
         clientRemoteEntityWorlds.Remove(remoteEntityWorld);
     }
 }
 private void UserManagementService_AddUserEvent(UserManagementServerNetworkService service,
     UserManagementServerNetworkService.UserInfo user)
 {
     if (World.Instance != null && EntitySystemWorld.Instance.IsServer())
         CreateClientRemoteEntityWorldAndSynchronizeWorld(user);
 }
 public ClientRemoteEntityWorld GetRemoteEntityWorld(
     UserManagementServerNetworkService.UserInfo user)
 {
     for (int n = 0; n < clientRemoteEntityWorlds.Count; n++)
     {
         ClientRemoteEntityWorld remoteEntityWorld = clientRemoteEntityWorlds[n];
         if (remoteEntityWorld.User == user)
             return remoteEntityWorld;
     }
     return null;
 }
Пример #17
0
            public ServerOrSingle_Player( uint identifier, string name, bool bot,
				UserManagementServerNetworkService.UserInfo user )
            {
                this.identifier = identifier;
                this.name = name;
                this.bot = bot;
                this.user = user;
            }
Пример #18
0
        void SendText( UserManagementServerNetworkService.UserInfo fromUser,
			string text, UserManagementServerNetworkService.UserInfo privateToUser )
        {
            if( ReceiveText != null )
                ReceiveText( this, fromUser, text, null );

            if( privateToUser != null )
            {
                if( privateToUser.ConnectedNode != null )
                    SendTextToClient( privateToUser, fromUser, text );
            }
            else
            {
                foreach( UserManagementServerNetworkService.UserInfo toUser in
                    userManagementService.Users )
                {
                    if( toUser.ConnectedNode != null )
                        SendTextToClient( toUser, fromUser, text );
                }
            }
        }
Пример #19
0
		void UserManagementService_RemoveUserEvent( UserManagementServerNetworkService sender,
			UserManagementServerNetworkService.UserInfo user )
		{
			listBoxUsers.Items.Remove( user );
			Log( "User disconnected: " + user.ToString() );
		}
 private void Server_ChatService_ReceiveText(ChatServerNetworkService sender,
     UserManagementServerNetworkService.UserInfo fromUser, string text,
     UserManagementServerNetworkService.UserInfo privateToUser)
 {
     string userName = fromUser != null ? fromUser.Name : "(null)";
     AddScreenMessage(string.Format("{0}: {1}", userName, text));
 }
 private void Server_UserManagementService_AddUserEvent(UserManagementServerNetworkService sender,
     UserManagementServerNetworkService.UserInfo user)
 {
     GameNetworkServer server = GameNetworkServer.Instance;
     //send map name to new client
     server.CustomMessagesService.SendToClient(user.ConnectedNode, "Lobby_MapName",
         SelectedMapName);
     //send AllowToConnectDuringGame flag to new client
     server.CustomMessagesService.SendToClient(user.ConnectedNode,
         "Lobby_AllowToConnectDuringGame", checkBoxAllowToConnectDuringGame.Checked.ToString());
 }
Пример #22
0
        public void Server_MoveBegin( UserManagementServerNetworkService.UserInfo user )
        {
            if( serverOrSingle_Moving )
                Log.Fatal( "JigsawPuzzlePiece: Server_BeginMoving: serverOrSingle_Moving == true." );

            serverOrSingle_Moving = true;
            serverOrSingle_movingTime = 0;
            server_movingByUser = user;

            //inform clients (send to the clients MoveBeginToClient message)
            SendDataWriter writer = BeginNetworkMessage( typeof( JigsawPuzzlePiece ),
                (ushort)NetworkMessages.MoveBeginToClient );
            writer.WriteVariableUInt32( server_movingByUser.Identifier );
            EndNetworkMessage();
        }
Пример #23
0
        public ServerOrSingle_Player ServerOrSingle_GetPlayer(
			UserManagementServerNetworkService.UserInfo user )
        {
            if( user == null )
                Log.Fatal( "PlayerManager: ServerOrSingle_GetPlayerByIntellect: user == null." );

            //it is can be slowly. need to use Dictionary.
            foreach( ServerOrSingle_Player player in serverOrSingle_players )
            {
                if( player.User == user )
                    return player;
            }
            return null;
        }
Пример #24
0
        void SendTextToClient( UserManagementServerNetworkService.UserInfo toUser,
			UserManagementServerNetworkService.UserInfo fromUser, string text )
        {
            MessageType messageType = GetMessageType( "textToClient" );
            SendDataWriter writer = BeginMessage( toUser.ConnectedNode, messageType );
            writer.WriteVariableUInt32( fromUser.Identifier );
            writer.Write( text );
            EndMessage();
        }
Пример #25
0
        public ServerOrSingle_Player Server_AddClientPlayer(
			UserManagementServerNetworkService.UserInfo user )
        {
            uint identifier = serverOrSingle_playerIdentifierCounter;
            serverOrSingle_playerIdentifierCounter++;

            ServerOrSingle_Player player = new ServerOrSingle_Player( identifier, user.Name, false,
                user );
            serverOrSingle_players.Add( player );

            Server_SendAddPlayerToClients( EntitySystemWorld.Instance.RemoteEntityWorlds, player );

            return player;
        }