Exemple #1
0
        private void OnClientConnected(IRoomClient roomClient)
        {
            roomClient.AfterReceive += OnClientReceive;
            roomClient.Disconnect   += OnDisconnect;

            lock (_clients)
                _clients.Add(roomClient);
        }
Exemple #2
0
        private void OnClientCommand(IRoomClient client, IRoomCommand command)
        {
            Action <IRemoteClient, IRoomCommand> handlerAction;

            if (_handlers.TryGetValue(command.Command, out handlerAction))
            {
                //ѕередача управлени¤ обработчику команды
                handlerAction((IRemoteClient)client, command);
            }
            else
            {
                //отключаем клиента, чтобы не слал что попало
                client.Detach();
            }
        }
Exemple #3
0
        private void OnClientReceive(IRoomClient client, IRoomCommand command)
        {
            switch (command.Command)
            {
            case Commands.SetClientId:
                client.ClientId = command.Data["ClientId"];
                SendClientCommand(client, cmd =>
                {
                    cmd.Command        = Commands.EnterToRoom;
                    cmd.Data["RoomId"] = client.Room;
                });
                break;

            case Commands.PushMessage:
                break;
            }
        }
Exemple #4
0
        private void SendClientCommand(IRoomClient client, Action <IRoomCommand> action)
        {
            IRoomCommand command = null;
            var          pool    = Container.Resolve <IPool <IRoomCommand> >();

            try
            {
                command = pool.Get();
                action(command);

                client.SendCommand(command);
            }
            catch (Exception e)
            {
                pool.Free(command);
            }
            finally
            {
                if (command != null)
                {
                    pool.Free(command);
                }
            }
        }