private void OnCommand(MessageReceived e) { switch (e.Packet) { case DevClientPackets.LoginAccepted: if (LoginReply != null) LoginReply(e.Packet, JsonSerializer.DeserializeFromString<LoginData>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.LoginFailed: if (LoginReply != null) LoginReply(e.Packet, null); break; case DevClientPackets.Banned: ServerKickBanMessage = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); break; case DevClientPackets.RegisterAccept: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.RegisterFailed: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.UserStats: if(UserStats != null) UserStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.TeamStats: if (TeamStats != null) TeamStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Pong: MessageBox.Show("PONG!: " + -(int)m_pingRequest.Subtract(DateTime.Now).TotalMilliseconds); break; case DevClientPackets.ServerMessage: if (ServerMessage != null) ServerMessage(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.ChannelUsers: if(ChannelUserList != null) ChannelUserList(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.AddChannelUser: if (AddUserToChannel != null) AddUserToChannel(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.RemoveChannelUser: if (RemoveUserFromChannel != null) RemoveUserFromChannel(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.UpdateUserInfo: if (UpdateUserInfo != null) UpdateUserInfo(JsonSerializer.DeserializeFromString<UserData>(Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.UserList: if (UserListUpdate != null) UserListUpdate(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.GameServers: var servers = JsonSerializer.DeserializeFromString<ServerInfo[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); foreach (ServerInfo server in servers.Where(server => !Program.ServerList.ContainsKey(server.serverName))) { Program.ServerList.Add(server.serverName, server); if (AddGameServer != null) AddGameServer(server.serverName); } break; case DevClientPackets.AddServer: var serverinfo = JsonSerializer.DeserializeFromString<ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (!Program.ServerList.ContainsKey(serverinfo.serverName)) { Program.ServerList.Add(serverinfo.serverName, serverinfo); if (AddGameServer != null) AddGameServer(serverinfo.serverName); } break; case DevClientPackets.RemoveServer: string removeserver = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (Program.ServerList.ContainsKey(removeserver)) { Program.ServerList.Remove(removeserver); if (RemoveGameServer != null) RemoveGameServer(removeserver); } break; case DevClientPackets.JoinChannelAccept: if (JoinChannel != null) JoinChannel(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.ChannelList: if (ChannelRequest != null) ChannelRequest(JsonSerializer.DeserializeFromString<ChannelData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.FriendList: if (FriendList != null) FriendList(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.TeamList: if (TeamList != null) TeamList(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.Message: if (ChatMessage != null) ChatMessage(JsonSerializer.DeserializeFromString<ChatMessage>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.DevPoints: if (DevPointMsg != null) DevPointMsg(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.DuelRequest: if (DuelRequest != null) DuelRequest(JsonSerializer.DeserializeFromString<DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.AcceptDuelRequest: string user = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (ChatMessage != null) ChatMessage(new ChatMessage(MessageType.Server, CommandType.None, null, user + " has accepted your duel request.")); break; case DevClientPackets.StartDuel: if(DuelAccepted != null) DuelAccepted(JsonSerializer.DeserializeFromString<DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RefuseDuelRequest: if(DuelRefused != null) DuelRefused(); break; case DevClientPackets.TeamRequest: if (TeamRequest != null) TeamRequest(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.GameList: if (AddRooms != null) AddRooms(JsonSerializer.DeserializeFromString<RoomInfos[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.CreateRoom: if (CreateRoom != null) CreateRoom(JsonSerializer.DeserializeFromString<RoomInfos>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RemoveRoom: if (RemoveRoom != null) RemoveRoom(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.UpdatePlayers: if (UpdateRoomPlayers != null) UpdateRoomPlayers(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RoomStart: if (UpdateRoomStatus != null) UpdateRoomStatus(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Kicked: ServerKickBanMessage = Encoding.UTF8.GetString(e.Raw); break; default: if (OnFatalError != null) OnFatalError("Unknown packet received: " + e.Packet.ToString()); break; } }
private void OnCommand(MessageReceived e) { switch (e.Packet) { case DevClientPackets.GameList: if (AddRooms != null) AddRooms(JsonSerializer.DeserializeFromString<RoomInfos[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.CreateRoom: if (CreateRoom != null) CreateRoom(JsonSerializer.DeserializeFromString<RoomInfos>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RemoveRoom: if (RemoveRoom != null) RemoveRoom(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.UpdatePlayers: if (UpdateRoomPlayers != null) UpdateRoomPlayers(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RoomStart: if (UpdateRoomStatus != null) UpdateRoomStatus(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Pong: MessageBox.Show("PONG!: " + -(int)m_pingRequest.Subtract(DateTime.Now).TotalMilliseconds); break; default: if (OnFatalError != null) OnFatalError("Unknown packet received: " + e.Packet.ToString()); break; } }
private void OnCommand(MessageReceived e) { switch (e.Packet) { case DevClientPackets.QueueFail: MessageBox.Show("You can only join once."); break; case DevClientPackets.MatchFound: if (MatchFound != null) { MatchFound(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.MatchCanceled: if (MatchCanceled != null) { MatchCanceled(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.MatchStart: if (MatchStart != null) { MatchStart(JsonSerializer.DeserializeFromString <DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.LoginAccepted: if (LoginReply != null) { LoginReply(e.Packet, JsonSerializer.DeserializeFromString <LoginData>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.LoginFailed: if (LoginReply != null) { LoginReply(e.Packet, null); } break; case DevClientPackets.Invalid: if (LoginReply != null) { LoginReply(e.Packet, null); } break; case DevClientPackets.InvalidTemp: if (LoginReply != null) { LoginReply(e.Packet, null); } break; case DevClientPackets.Banned: IsUserBanned = true; ServerKickBanMessage = Encoding.UTF8.GetString(e.Raw); MessageBox.Show(ServerKickBanMessage, "Server", MessageBoxButtons.OK); Application.Exit(); break; case DevClientPackets.RegisterAccept: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.RegisterFailed: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.DuplicateMail: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.BlacklistMail: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.BlacklistName: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.MailFormat: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.ChangeAccept: if (ChangeReply != null) { ChangeReply(e.Packet); } break; case DevClientPackets.ChangeFailed: if (ChangeReply != null) { ChangeReply(e.Packet); } break; case DevClientPackets.ValidateAccept: if (ValidateReply != null) { ValidateReply(e.Packet); } break; case DevClientPackets.ValidateFailed: if (ValidateReply != null) { ValidateReply(e.Packet); } break; case DevClientPackets.ResendAccept: if (ResendReply != null) { ResendReply(e.Packet); } break; case DevClientPackets.ResendFailed: if (ResendReply != null) { ResendReply(e.Packet); } break; case DevClientPackets.RecoverAccept: if (RecoverReply != null) { RecoverReply(e.Packet); } break; case DevClientPackets.RecoverFailed: if (RecoverReply != null) { RecoverReply(e.Packet); } break; case DevClientPackets.ResetAccept: if (ResetReply != null) { ResetReply(e.Packet); } break; case DevClientPackets.ResetFailed: if (ResetReply != null) { ResetReply(e.Packet); } break; case DevClientPackets.UserStats: if (UserStats != null) { UserStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.TeamStats: if (TeamStats != null) { TeamStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.Ranking: //MessageBox.Show(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (Ranking != null) { Ranking(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.Pong: MessageBox.Show("PONG!: " + -(int)m_pingRequest.Subtract(DateTime.Now).TotalMilliseconds); break; case DevClientPackets.ServerMessage: if (ServerMessage != null) { ServerMessage(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.ChannelUsers: if (ChannelUserList != null) { ChannelUserList(JsonSerializer.DeserializeFromString <ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); } break; case DevClientPackets.AddChannelUser: if (AddUserToChannel != null) { AddUserToChannel(JsonSerializer.DeserializeFromString <ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); } break; case DevClientPackets.RemoveChannelUser: if (RemoveUserFromChannel != null) { RemoveUserFromChannel(JsonSerializer.DeserializeFromString <ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); } break; case DevClientPackets.UpdateUserInfo: if (UpdateUserInfo != null) { UpdateUserInfo(JsonSerializer.DeserializeFromString <UserData>(Encoding.UTF8.GetString(e.Raw))); } break; case DevClientPackets.UserList: if (UserListUpdate != null) { UserListUpdate(JsonSerializer.DeserializeFromString <UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.GameServers: var servers = JsonSerializer.DeserializeFromString <ServerInfo[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); foreach (ServerInfo server in servers) { if (server.serverName.Contains("DevServer") && !Program.ServerList.ContainsKey(server.serverName)) { Program.ServerList.Add(server.serverName, server); } else if (!Program.ServerList3P.ContainsKey(server.serverName)) { Program.ServerList3P.Add(server.serverName, server); } } break; case DevClientPackets.AddServer: var serverinfo = JsonSerializer.DeserializeFromString <ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (serverinfo.serverName.Contains("DevServer") && !Program.ServerList.ContainsKey(serverinfo.serverName)) { Program.ServerList.Add(serverinfo.serverName, serverinfo); } else if (!Program.ServerList3P.ContainsKey(serverinfo.serverName)) { Program.ServerList3P.Add(serverinfo.serverName, serverinfo); } break; case DevClientPackets.RemoveServer: string removeserver = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (removeserver.Contains("DevServer") && Program.ServerList.ContainsKey(removeserver)) { Program.ServerList.Remove(removeserver); } else if (Program.ServerList3P.ContainsKey(removeserver)) { Program.ServerList3P.Remove(removeserver); } break; case DevClientPackets.UpdateServerStatus: ServerInfo serverInfo = JsonSerializer.DeserializeFromString <ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); Program.ServerList[serverInfo.serverName] = serverInfo; break; case DevClientPackets.JoinChannelAccept: if (JoinChannel != null) { JoinChannel(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.ChannelList: if (ChannelRequest != null) { ChannelRequest(JsonSerializer.DeserializeFromString <ChannelData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.FriendList: if (FriendList != null) { FriendList(JsonSerializer.DeserializeFromString <UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.TeamList: if (TeamList != null) { TeamList(JsonSerializer.DeserializeFromString <UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.Message: if (ChatMessage != null) { ChatMessage(JsonSerializer.DeserializeFromString <ChatMessage>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.DevPoints: if (DevPointMsg != null) { DevPointMsg(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.DuelRequest: if (DuelRequest != null) { DuelRequest(JsonSerializer.DeserializeFromString <DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.AcceptDuelRequest: string user = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (ChatMessage != null) { ChatMessage(new ChatMessage(MessageType.Server, CommandType.None, null, user + " has accepted your duel request.")); } break; case DevClientPackets.StartDuel: if (DuelAccepted != null) { DuelAccepted(JsonSerializer.DeserializeFromString <DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RefuseDuelRequest: if (DuelRefused != null) { DuelRefused(); } break; case DevClientPackets.TeamRequest: if (TeamRequest != null) { TeamRequest(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.GameList: if (AddRooms != null) { AddRooms(JsonSerializer.DeserializeFromString <RoomInfos[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.CreateRoom: if (CreateRoom != null) { CreateRoom(JsonSerializer.DeserializeFromString <RoomInfos>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RemoveRoom: if (RemoveRoom != null) { RemoveRoom(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.UpdatePlayers: if (UpdateRoomPlayers != null) { UpdateRoomPlayers(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RoomStart: if (UpdateRoomStatus != null) { UpdateRoomStatus(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.Kicked: ServerKickBanMessage = Encoding.UTF8.GetString(e.Raw) + "\n\r Do you want to restart DevPro ?"; break; default: if (OnFatalError != null) { OnFatalError("Unknown packet received: " + e.Packet.ToString()); } break; } }
private void OnCommand(MessageReceived e) { switch (e.Packet) { case DevClientPackets.LoginAccepted: if (LoginReply != null) { LoginReply(e.Packet, JsonSerializer.DeserializeFromString <LoginData>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.LoginFailed: if (LoginReply != null) { LoginReply(e.Packet, null); } break; case DevClientPackets.Banned: string message = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (string.IsNullOrEmpty(message)) { if (Banned != null) { Banned("You are banned."); } } else { if (Banned != null) { Banned(message); } } break; case DevClientPackets.RegisterAccept: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.RegisterFailed: if (RegisterReply != null) { RegisterReply(e.Packet); } break; case DevClientPackets.UserStats: if (UserStats != null) { UserStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.TeamStats: if (TeamStats != null) { TeamStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.Pong: MessageBox.Show("PONG!: " + -(int)m_pingRequest.Subtract(DateTime.Now).TotalMilliseconds); break; case DevClientPackets.ServerMessage: if (ServerMessage != null) { ServerMessage(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.AddUser: if (AddUser != null) { AddUser(JsonSerializer.DeserializeFromString <UserData>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RemoveUser: if (RemoveUser != null) { RemoveUser(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.UserList: if (AddUsers != null) { AddUsers(JsonSerializer.DeserializeFromString <UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.GameServers: var servers = JsonSerializer.DeserializeFromString <ServerInfo[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); foreach (ServerInfo server in servers.Where(server => !Program.ServerList.ContainsKey(server.serverName))) { Program.ServerList.Add(server.serverName, server); if (AddGameServer != null) { AddGameServer(server.serverName); } } break; case DevClientPackets.AddServer: var serverinfo = JsonSerializer.DeserializeFromString <ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (!Program.ServerList.ContainsKey(serverinfo.serverName)) { Program.ServerList.Add(serverinfo.serverName, serverinfo); if (AddGameServer != null) { AddGameServer(serverinfo.serverName); } } break; case DevClientPackets.RemoveServer: string removeserver = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (Program.ServerList.ContainsKey(removeserver)) { Program.ServerList.Remove(removeserver); if (RemoveGameServer != null) { RemoveGameServer(removeserver); } } break; case DevClientPackets.JoinChannelAccept: if (JoinChannel != null) { JoinChannel(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.ChannelList: if (ChannelRequest != null) { ChannelRequest(JsonSerializer.DeserializeFromString <ChannelData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.FriendList: if (FriendList != null) { FriendList(JsonSerializer.DeserializeFromString <string[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.TeamList: if (TeamList != null) { TeamList(JsonSerializer.DeserializeFromString <string[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.Message: if (ChatMessage != null) { ChatMessage(JsonSerializer.DeserializeFromString <ChatMessage>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.DevPoints: if (DevPointMsg != null) { DevPointMsg(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.DuelRequest: if (DuelRequest != null) { DuelRequest(JsonSerializer.DeserializeFromString <DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.AcceptDuelRequest: string user = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (ChatMessage != null) { ChatMessage(new ChatMessage(MessageType.Server, CommandType.None, null, user + " has accepted your duel request.")); } break; case DevClientPackets.StartDuel: if (DuelAccepted != null) { DuelAccepted(JsonSerializer.DeserializeFromString <DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RefuseDuelRequest: if (DuelRefused != null) { DuelRefused(); } break; case DevClientPackets.TeamRequest: if (TeamRequest != null) { TeamRequest(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.GameList: if (AddRooms != null) { AddRooms(JsonSerializer.DeserializeFromString <RoomInfos[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.CreateRoom: if (CreateRoom != null) { CreateRoom(JsonSerializer.DeserializeFromString <RoomInfos>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RemoveRoom: if (RemoveRoom != null) { RemoveRoom(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.UpdatePlayers: if (UpdateRoomPlayers != null) { UpdateRoomPlayers(JsonSerializer.DeserializeFromString <PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); } break; case DevClientPackets.RoomStart: if (UpdateRoomStatus != null) { UpdateRoomStatus(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; case DevClientPackets.Kicked: if (Kicked != null) { Kicked(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); } break; default: if (OnFatalError != null) { OnFatalError("Unknown packet received: " + e.Packet.ToString()); } break; } }
private void OnCommand(MessageReceived e) { switch (e.Packet) { case DevClientPackets.QueueFail: MessageBox.Show("You can only join once."); break; case DevClientPackets.MatchFound: if (MatchFound != null) MatchFound(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.MatchCanceled: if (MatchCanceled != null) MatchCanceled(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.MatchStart: if (MatchStart != null) MatchStart(JsonSerializer.DeserializeFromString<DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.LoginAccepted: if (LoginReply != null) LoginReply(e.Packet, JsonSerializer.DeserializeFromString<LoginData>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.LoginFailed: if (LoginReply != null) LoginReply(e.Packet, null); break; case DevClientPackets.Invalid: if (LoginReply != null) LoginReply(e.Packet, null); break; case DevClientPackets.InvalidTemp: if (LoginReply != null) LoginReply(e.Packet, null); break; case DevClientPackets.Banned: IsUserBanned = true; ServerKickBanMessage = Encoding.UTF8.GetString(e.Raw); MessageBox.Show(ServerKickBanMessage, "Server", MessageBoxButtons.OK); Application.Exit(); break; case DevClientPackets.RegisterAccept: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.RegisterFailed: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.DuplicateMail: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.BlacklistMail: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.BlacklistName: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.MailFormat: if (RegisterReply != null) RegisterReply(e.Packet); break; case DevClientPackets.ChangeAccept: if (ChangeReply != null) ChangeReply(e.Packet); break; case DevClientPackets.ChangeFailed: if (ChangeReply != null) ChangeReply(e.Packet); break; case DevClientPackets.ValidateAccept: if (ValidateReply != null) ValidateReply(e.Packet); break; case DevClientPackets.ValidateFailed: if (ValidateReply != null) ValidateReply(e.Packet); break; case DevClientPackets.ResendAccept: if (ResendReply != null) ResendReply(e.Packet); break; case DevClientPackets.ResendFailed: if (ResendReply != null) ResendReply(e.Packet); break; case DevClientPackets.RecoverAccept: if (RecoverReply != null) RecoverReply(e.Packet); break; case DevClientPackets.RecoverFailed: if (RecoverReply != null) RecoverReply(e.Packet); break; case DevClientPackets.ResetAccept: if (ResetReply != null) ResetReply(e.Packet); break; case DevClientPackets.ResetFailed: if (ResetReply != null) ResetReply(e.Packet); break; case DevClientPackets.UserStats: if (UserStats != null) UserStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.TeamStats: if (TeamStats != null) TeamStats(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Ranking: //MessageBox.Show(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (Ranking != null) Ranking(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Pong: MessageBox.Show("PONG!: " + -(int)m_pingRequest.Subtract(DateTime.Now).TotalMilliseconds); break; case DevClientPackets.ServerMessage: if (ServerMessage != null) ServerMessage(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.ChannelUsers: if (ChannelUserList != null) ChannelUserList(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.AddChannelUser: if (AddUserToChannel != null) AddUserToChannel(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.RemoveChannelUser: if (RemoveUserFromChannel != null) RemoveUserFromChannel(JsonSerializer.DeserializeFromString<ChannelUsers>( Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.UpdateUserInfo: if (UpdateUserInfo != null) UpdateUserInfo(JsonSerializer.DeserializeFromString<UserData>(Encoding.UTF8.GetString(e.Raw))); break; case DevClientPackets.UserList: if (UserListUpdate != null) UserListUpdate(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.GameServers: var servers = JsonSerializer.DeserializeFromString<ServerInfo[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); foreach (ServerInfo server in servers) { if (server.serverName.Contains("DevServer") && !Program.ServerList.ContainsKey(server.serverName)) { Program.ServerList.Add(server.serverName, server); } else if (!Program.ServerList3P.ContainsKey(server.serverName)) { Program.ServerList3P.Add(server.serverName, server); } } break; case DevClientPackets.AddServer: var serverinfo = JsonSerializer.DeserializeFromString<ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); if (serverinfo.serverName.Contains("DevServer") && !Program.ServerList.ContainsKey(serverinfo.serverName)) { Program.ServerList.Add(serverinfo.serverName, serverinfo); } else if (!Program.ServerList3P.ContainsKey(serverinfo.serverName)) { Program.ServerList3P.Add(serverinfo.serverName, serverinfo); } break; case DevClientPackets.RemoveServer: string removeserver = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (removeserver.Contains("DevServer") && Program.ServerList.ContainsKey(removeserver)) { Program.ServerList.Remove(removeserver); } else if (Program.ServerList3P.ContainsKey(removeserver)) { Program.ServerList3P.Remove(removeserver); } break; case DevClientPackets.UpdateServerStatus: ServerInfo serverInfo = JsonSerializer.DeserializeFromString<ServerInfo>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); Program.ServerList[serverInfo.serverName] = serverInfo; break; case DevClientPackets.JoinChannelAccept: if (JoinChannel != null) JoinChannel(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.ChannelList: if (ChannelRequest != null) ChannelRequest(JsonSerializer.DeserializeFromString<ChannelData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.FriendList: if (FriendList != null) FriendList(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.TeamList: if (TeamList != null) TeamList(JsonSerializer.DeserializeFromString<UserData[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.Message: if (ChatMessage != null) ChatMessage(JsonSerializer.DeserializeFromString<ChatMessage>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.DevPoints: if (DevPointMsg != null) DevPointMsg(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.DuelRequest: if (DuelRequest != null) DuelRequest(JsonSerializer.DeserializeFromString<DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.AcceptDuelRequest: string user = Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)); if (ChatMessage != null) ChatMessage(new ChatMessage(MessageType.Server, CommandType.None, null, user + " has accepted your duel request.")); break; case DevClientPackets.StartDuel: if (DuelAccepted != null) DuelAccepted(JsonSerializer.DeserializeFromString<DuelRequest>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RefuseDuelRequest: if (DuelRefused != null) DuelRefused(); break; case DevClientPackets.TeamRequest: if (TeamRequest != null) TeamRequest(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.GameList: if (AddRooms != null) AddRooms(JsonSerializer.DeserializeFromString<RoomInfos[]>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.CreateRoom: if (CreateRoom != null) CreateRoom(JsonSerializer.DeserializeFromString<RoomInfos>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RemoveRoom: if (RemoveRoom != null) RemoveRoom(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.UpdatePlayers: if (UpdateRoomPlayers != null) UpdateRoomPlayers(JsonSerializer.DeserializeFromString<PacketCommand>(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length)))); break; case DevClientPackets.RoomStart: if (UpdateRoomStatus != null) UpdateRoomStatus(Encoding.UTF8.GetString(e.Reader.ReadBytes(e.Raw.Length))); break; case DevClientPackets.Kicked: ServerKickBanMessage = Encoding.UTF8.GetString(e.Raw) + "\n\r Do you want to restart DevPro ?"; break; default: if (OnFatalError != null) OnFatalError("Unknown packet received: " + e.Packet.ToString()); break; } }