protected void HandlePacket_VNET_LOGON(User user, PacketReader reader) { string username = reader.ReadStringNT(); string password = reader.ReadStringNT(); string client = reader.ReadStringNT(); string dcMsg = ""; if ((dcMsg = GetDisconnectMessage(username, password, client)) != "") { DisconnectUser(user, dcMsg); return; } //check client name with saved client list //check username+pass combo AccountState state = GetAccountState(username, password); if (state == AccountState.InvalidPassword) { SendLogonResult(user, LogonResult.InvalidPassword); return; } if (state == AccountState.NewAccount) CreateNewAccount(username, password, user.IPAddress); //check challenge (if any) if (GetUserByName(username) != null) { SendLogonResult(user, LogonResult.AccountInUse); return; } user.Username = username; user.Client = client; user.IsOnline = true; ServerStats.usersOnline++; ConsoleSendUserJoinServer(user); UpdateLastLogin(username); SendLogonResult(user, LogonResult.Success); if (state == AccountState.NewAccount) SendServerInfo(user, "New account created!"); JoinUserToChannel(user, Channel_Main); }
protected void HandlePacket_VNET_SERVERCHALLENGE(User user, PacketReader reader) { string GrabChallenge = reader.ReadStringNT(); if (IsEmptyChallenge(user.Username, GrabChallenge)) InsertChallenge(user.Username, GrabChallenge); else { if (!GetChallengeState(user.Username, GrabChallenge)) { DisconnectUser(user, "You have provided an incorrect challenge."); } } }
protected void HandlePacket_VNET_CHATEVENT(User user, PacketReader reader) { string text = reader.ReadStringNT(); if (ContainsNonPrintable(text)) { SendServerError(user, "Chat events cannot contain non-printable characters"); return; } if (text[0] == '/') HandleCommand(user, text.Substring(1)); else UserTalk(user, text); }
protected void HandleAppID(User fromSend, PacketReader reader) { byte getAppID = reader.ReadByte(); if (getAppID > 0x05) { SendServerError(fromSend, "You have send an invalid app ID."); return; } byte getAppFlagStatus = reader.ReadByte(); User toSend = GetUserByName(reader.ReadStringNT()); toSend.Packet.Clear().InsertByte(getAppID) .InsertByte(getAppFlagStatus) .InsertStringNT(fromSend.Username); switch ((AppFlags)getAppID) { case AppFlags.Unhandled: toSend.Packet.Send(VNET_APPS); break; case AppFlags.TicTacToe: byte tttEventID = reader.ReadByte(); if (tttEventID == 0x06) { Random num = new Random(); int numRand = num.Next(1); byte result = (byte)(numRand == 0 ? 0x01 : 0x02); toSend.Packet.InsertByte(tttEventID) .InsertByte(result) .Send(VNET_APPS); } else toSend.Packet.InsertByte(tttEventID).InsertString(reader.ReadToEnd().ToString()); break; case AppFlags.VNetPad: toSend.Packet.Clear().InsertString(reader.ReadToEnd().ToString()).Send(VNET_APPS); break; } }
protected void HandlePacket(PacketReader reader) { User user; string username; string client; string channel; string text; int ping; byte flags; byte id; short count; byte tmpByte = 0; string tmpStr = ""; try { byte packetId = reader.ReadByte(); switch (packetId) { case VNET_LOGON: //0x01 LogonResult logonResult = (LogonResult)reader.ReadByte(); byte challengeByte = reader.ReadByte(); string serverVersion = reader.ReadStringNT(); string hostedBy = reader.ReadStringNT(); MyName = reader.ReadStringNT(); ping = reader.ReadDword(); flags = reader.ReadByte(); if (logonResult == LogonResult.Success || logonResult == LogonResult.SendChallenge) { AddChat(ChatColors.ServerInfo, "Successfully logged on"); } else if (logonResult == LogonResult.InvalidPassword) AddChat(ChatColors.ServerError, "Invalid password"); else if (logonResult == LogonResult.InvalidUsername) AddChat(ChatColors.ServerError, "Invalid username"); else if (logonResult == LogonResult.AccountInUse) AddChat(ChatColors.ServerError, "Account is in use"); break; case VNET_CHATEVENT: //0x03 id = reader.ReadByte(); ping = reader.ReadDword(); flags = reader.ReadByte(); username = reader.ReadStringNT(); text = reader.ReadStringNT(); if (id == (byte)ChatEventType.UserJoinedServer) { } else if (id == (byte)ChatEventType.UserLeftServer) { } else if (id == (byte)ChatEventType.UserTalk) { AddChat(ChatColors.ChatOther, "<", ChatColors.UsernameRemote, username, ChatColors.ChatOther, "> ", ChatColors.ChatMsg, text); } else if (id == (byte)ChatEventType.UserEmote) { AddChat(ChatColors.EmoteOther, "<", ChatColors.UsernameRemote, username, ChatColors.EmoteOther, "> ", ChatColors.EmoteMsg, text); } else if (id == (byte)ChatEventType.ServerInfo) { if (flags == 0x01) //error AddChat(ChatColors.ServerError, "[VNET] " + text); else if (flags == 0x02) //info AddChat(ChatColors.ServerInfo, "[VNET] " + text); else if (flags == 0x03) //acct-message AddChat(ChatColors.ServerError, "[VNET] " + text); else if (flags == 0x04) //broadcast AddChat(ChatColors.UsernameBroadcast, "<" + username + "> " + text); else if (flags == 0x05) //joined channel AddChat(ChatColors.UserJoinedChannel, "-- You joined channel ", ChatColors.UserJoinedChannel_Channel, text, ChatColors.UserJoinedChannel, " --"); } else if (id == (byte)ChatEventType.UserJoinedChannel) { AddUser(new User() { Username = username, Client = text, Flags = (UserFlags)flags, Ping = ping }); AddChat(ChatColors.UserJoinedChannel, "-- ", ChatColors.UserJoinedChannel_Username, username, ChatColors.UserJoinedChannel, " [0x" + flags.ToString("X") + "] has joined the channel --"); } else if (id == (byte)ChatEventType.UserLeftChannel) { RemoveUser(username); AddChat(ChatColors.UserJoinedChannel, "-- ", ChatColors.UserJoinedChannel_Username, username, ChatColors.UserJoinedChannel, " has left the channel --"); } break; case VNET_LIST: //0x06 id = reader.ReadByte(); count = reader.ReadWord(); if (id == (byte)ListType.UsersInChannel) ClearChannelList(); else if (id == (byte)ListType.UsersOnServer) AddChat(ChatColors.ServerInfo, "Users on server:"); while (!reader.EOF()) { username = reader.ReadStringNT(); client = reader.ReadStringNT(); if (id == (byte)ListType.UsersOnServer) { channel = reader.ReadStringNT(); tmpByte = reader.ReadByte(); if (tmpByte != 0) tmpStr = reader.ReadStringNT(); } ping = reader.ReadDword(); flags = reader.ReadByte(); if (id == (byte)ListType.UsersInChannel) { user = new User() { Username = username, Client = client, Ping = ping, Flags = (UserFlags)flags }; AddUser(user); } else if (id == (byte)ListType.UsersBannedFromChannel) { } else if (id == (byte)ListType.UsersOnServer) { AddChat(ChatColors.ServerInfo, " " + username + (tmpByte == 0 ? "" : " - Banned from: " + tmpStr.Replace(((char)1).ToString(), ", "))); } } break; default: AddChat(ChatColors.ServerError, "Unknown packet " + packetId.ToString() + ": " + Encoding.ASCII.GetString(reader.ReadToEnd()).Replace((char)0, '.')); break; } } catch (Exception ex) { } }