private void ProcessMessage(Message msg, ServerClient c) { byte[] data = msg.Data; byte header = data[0]; if (Debug.DebugMode && data[0] != MsgHeader.PlayerPos) PrintMsg(data); switch (header) { case MsgHeader.Null: break; case MsgHeader.ClientReady: InitNewPlayer(c, data); break; case MsgHeader.PlayerPos: UpdatePlayerPos(c, data); break; case MsgHeader.Chat: RelayMessage(c, data, RelaySwitch.All); break; case MsgHeader.Quit: //tell everyone in the room to disconnect foreach (var c1 in c.Room.Clients.Where(c2 => c2 != c)) c1.SendRemovePlayer(c); break; default: throw new ArgumentException("Unhandled message received by server"); } }
private void ProcessMessage(Message msg) { if (Transfering) return; byte[] data = msg.Data; byte header = data[0]; if (Debug.DebugMode && data[0] != MsgHeader.PlayerPos && data[0] != MsgHeader.Mobpos) PrintMsg(data); switch (header) { case MsgHeader.Null: break; case MsgHeader.Welcome: Globals.Client.ReceivedWelcomeMessage = true; break; case MsgHeader.AddPlayer: AddPlayer(data); break; case MsgHeader.RemovePlayer: RemovePlayer(data); break; case MsgHeader.PlayerPos: UpdatePlayerPos(data); break; case MsgHeader.Chat: PostChat(data); break; case MsgHeader.Newmob: AddMob(data); break; case MsgHeader.Mobpos: UpdateMobPos(data); break; default: throw new ArgumentException("Unhandled message received by client"); } }
protected void Dispatch(List<byte> msgBuffer) { var newMsg = new Message(); newMsg.Data = new byte[msgBuffer[0]]; msgBuffer.CopyTo(1, newMsg.Data, 0, msgBuffer[0]); zMessages.Enqueue(newMsg); }