Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-----MMO World Server-----");
            Console.WriteLine("Checking DB connection");
            string databaseStatus = WorldDatabase.SetupConnection();

            if (databaseStatus == "OK")
            {
                Console.WriteLine("Connected to DB.");
                WorldServer server      = new WorldServer();
                bool        startServer = server.StartServer();
                while (startServer)
                {
                    string input = Console.ReadLine();
                    //TODO: allow for commands to be entered into the server here
                }
                //Thread.Sleep(10000);
            }
            else
            {
                Console.WriteLine("FAILED. Could not connect to MYSQL DB.");
                Console.WriteLine("Please press any key to continue...");
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        private void SaveCharacterPositions(object state)
        {
            ConcurrentDictionary <uint, Character> players = (ConcurrentDictionary <uint, Character>)state;

            foreach (var entry in players)
            {
                var character = entry.Value;
                Console.WriteLine("Saving character position for: " + character.CharacterId);
                WorldDatabase.UpdateCharacterPosition(character.CharacterId, character.XPos, character.YPos, character.Zone);
            }
        }
Ejemplo n.º 3
0
 public void Disconnect()
 {
     if (Character != null)
     {
         WorldDatabase.RemoveFromOnlinePlayerList(Character.CharacterId);
     }
     if (socket.Connected)
     {
         socket.Disconnect(false);
     }
 }
Ejemplo n.º 4
0
        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;
                }
            }
        }