public static CharacterPositionsWrapper GetCharacterPosition(uint characterId) { CharacterPositionsWrapper wrapper = new CharacterPositionsWrapper() { CharacterId = characterId }; MySqlCommand command = conn.CreateCommand(); command.CommandText = "SELECT * from character_positions where characterId=@characterId"; command.Parameters.AddWithValue("@characterId", characterId); MySqlDataReader rdr = command.ExecuteReader(); rdr.Read(); if (rdr.HasRows) { if (rdr.GetUInt32(0) != characterId) { throw new Exception("Weird case, found record but does not match"); } wrapper.XPos = rdr.GetFloat(1); wrapper.YPos = rdr.GetFloat(2); wrapper.Zone = rdr.GetString(3); rdr.Close(); return(wrapper); } else { throw new Exception("Could not find character_positions record for character id: " + characterId); } }
private void ProcessConnectPackets(List <SubPacket> subPackets) { foreach (SubPacket subPacket in subPackets) { subPacket.debugPrintSubPacket(); switch (subPacket.gameMessage.opcode) { case ((ushort)GamePacketOpCode.Handshake): try { Console.WriteLine("100% CORRECT CLIENT CONNECTION: " + client.GetFullAddress()); ConfirmClientConnectionWithLoginServer(new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp), subPacket); } catch (Exception e) { Console.WriteLine(e); } break; case (((ushort)GamePacketOpCode.Acknowledgement)): AcknowledgePacket ack = new AcknowledgePacket(subPacket.data); if (ack.AckSuccessful) { if (WorldServer.mConnectedPlayerList.TryGetValue(ack.CharacterId, out Character character)) { client.Disconnect(); //this is 100% login server connection, don't doubt this client = character.WorldClientConnection; client.Character = character; CharacterPositionsWrapper posDbWrapper = WorldDatabase.GetCharacterPosition(client.Character.CharacterId); client.Character.XPos = posDbWrapper.XPos; client.Character.YPos = posDbWrapper.YPos; client.Character.Zone = posDbWrapper.Zone; Console.WriteLine("Client looks legit: " + (ack.ClientAddress == client.GetIp())); WorldDatabase.AddToOnlinePlayerList(character.CharacterId, ack.ClientAddress); client.SessionId = WorldDatabase.GetSessionId(character.CharacterId); Console.WriteLine("Sending ack received from login server back to: " + client.GetFullAddress()); AcknowledgePacket responseAck = new AcknowledgePacket(ack.AckSuccessful, client.SessionId); SubPacket sp = new SubPacket(GamePacketOpCode.Acknowledgement, 0, 0, responseAck.GetResponseFromWorldServerBytes(), SubPacketTypes.GamePacket); client.QueuePacket(BasePacket.CreatePacket(sp, true, false)); client.FlushQueuedSendPackets(); break; } else { Console.WriteLine("Client has connected but is not in Connected Player List.. Not sure what to do here"); } } else { Console.WriteLine("Ack not successful, removing from connected player list"); WorldServer.mConnectedPlayerList.TryRemove(ack.CharacterId, out Character unsuccessfulAckCharacter); client.Disconnect(); } break; case (((ushort)GamePacketOpCode.Disconnect)): DisconnectPacket dc = new DisconnectPacket(subPacket.data); Console.WriteLine("Got DC packet"); WorldDatabase.RemoveFromOnlinePlayerList(dc.CharacterId); WorldServer.mConnectedPlayerList.TryRemove(dc.CharacterId, out Character characterToDc); client.Disconnect(); break; //if everything okay default: break; } } }