private void OnClientConnected(IRoomClient roomClient) { roomClient.AfterReceive += OnClientReceive; roomClient.Disconnect += OnDisconnect; lock (_clients) _clients.Add(roomClient); }
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(); } }
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; } }
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); } } }