protected virtual void OnRemoteEvent(RemoteEvent evt)
 {
     switch (evt.Event)
     {
     case RemoteEvent.Evt.ChatMessage:
         if (ChatMessage != null)
         {
             ChatMessage(evt.Error, evt.Get <ChatMessage>(0));
         }
         break;
     }
 }
        public void Broadcast(RemoteEvent.Evt evt, Error error, ServerEventArgs globalArgs, params RemoteArg[] args)
        {
            RemoteEvent remoteEvent = new RemoteEvent(evt, error, args);

            byte[] result = m_serializer.Serialize(remoteEvent);
            if (globalArgs.Targets != null && globalArgs.Targets.Length > 0)
            {
                Broadcast(globalArgs.Targets, result);
            }
            else
            {
                BroadcastAllExcept(globalArgs.Except, result);
            }
        }
        protected override void OnRemoteEvent(RemoteEvent evt)
        {
            switch (evt.Event)
            {
            case RemoteEvent.Evt.Tick:
                if (Tick != null)
                {
                    Tick(evt.Error, evt.Get <CommandsBundle>(0));
                }
                break;

            case RemoteEvent.Evt.Ping:
                if (Ping != null)
                {
                    Ping(evt.Error, evt.Get <RTTInfo>(0));
                }
                break;

            case RemoteEvent.Evt.Pause:
                if (Paused != null)
                {
                    Paused(evt.Error, evt.Get <bool>(0));
                }
                break;

            case RemoteEvent.Evt.ReadyToPlayAll:
                if (ReadyToPlayAll != null)
                {
                    ReadyToPlayAll(evt.Error,
                                   evt.Get <Player[]>(0),
                                   evt.Get <Guid[]>(1),
                                   evt.Get <VoxelAbilitiesArray[]>(2),
                                   evt.Get <SerializedTaskArray[]>(3),
                                   evt.Get <SerializedTaskTemplatesArray[]>(4),
                                   evt.Get <AssignmentGroupArray[]>(5),
                                   evt.Get <Room>(6));
                }
                break;

            default:
                base.OnRemoteEvent(evt);
                break;
            }
        }
        protected void Send(RemoteEvent.Evt evt, Error error, Guid target, params RemoteArg[] args)
        {
            RemoteEvent remoteEvent = new RemoteEvent(evt, error, args);

            byte[] data = m_serializer.Serialize(remoteEvent);

            lock (m_protocolToClientId)
            {
                lock (m_outgoingMessages)
                {
                    Guid         clientId = target;
                    ILowProtocol protocol;

                    if (m_clientIdToProtocol.TryGetValue(clientId, out protocol))
                    {
                        EnqueueSend(protocol, data);
                    }
                }
            }
        }
        protected virtual void OnMessage(ILowProtocol sender, byte[] args)
        {
            RemoteEvent evt = m_serializer.Deserialize <RemoteEvent>(args);

            OnRemoteEvent(evt);
        }
        protected override void OnRemoteEvent(RemoteEvent evt)
        {
            switch (evt.Event)
            {
            case RemoteEvent.Evt.JoinedRoom:
                if (JoinedRoom != null)
                {
                    JoinedRoom(evt.Error, evt.Get <Guid[]>(0), evt.Get <Room>(1));
                }
                break;

            case RemoteEvent.Evt.Launched:
            {
                string matchServerUrl = evt.Get <string>(0);
                Dependencies.State.SetValue("Battlehub.VoxelCombat.MatchServerUrl", matchServerUrl);
                if (Launched != null)
                {
                    Launched(evt.Error, matchServerUrl);
                }
            }
            break;

            case RemoteEvent.Evt.LeftRoom:
                if (LeftRoom != null)
                {
                    LeftRoom(evt.Error, evt.Get <Guid[]>(0), evt.Get <Room>(1));
                }
                break;

            case RemoteEvent.Evt.LoggedIn:
                if (LoggedIn != null)
                {
                    LoggedIn(evt.Error, evt.Get <Guid>(0));
                }
                break;

            case RemoteEvent.Evt.LoggedOff:
                if (LoggedOff != null)
                {
                    LoggedOff(evt.Error, evt.Get <Guid[]>(0));
                }
                break;

            case RemoteEvent.Evt.ReadyToLaunch:
                if (ReadyToLaunch != null)
                {
                    ReadyToLaunch(evt.Error, evt.Get <Room>(0));
                }
                break;

            case RemoteEvent.Evt.RoomDestroyed:
                if (RoomDestroyed != null)
                {
                    RoomDestroyed(evt.Error);
                }
                break;

            case RemoteEvent.Evt.RoomsListChanged:
                if (RoomsListChanged != null)
                {
                    RoomsListChanged(evt.Error);
                }
                break;

            default:
                base.OnRemoteEvent(evt);
                break;
            }
        }