Exemple #1
0
    public static void MakeClientConnectToGameServer(DataTable result, int cid, int forcedMap = -1)
    {
        AuthCore core = (AuthCore)Server.the_core;

        Int32.TryParse(result.Rows[0]["map"].ToString(), out int map);
        Int32.TryParse(result.Rows[0]["id"].ToString(), out int pid);
        if (forcedMap > 0)
        {
            map = forcedMap;
        }

        foreach (GameServer server in Config.GameServers)
        {
            if (server.maps.Contains(map))
            {
                using (Packet nPacket = new Packet((int)Packet.ServerPackets.goToServerAt))
                {
                    nPacket.Write(cid);
                    nPacket.Write(core.Clients[cid].session_id);
                    nPacket.Write(server.addr);
                    nPacket.Write(server.port);
                    AuthCore.SendTCPData(cid, nPacket);
                }

                Logger.Syslog($"Client #{cid} is entering map #{map} on the server labeled '{server.label}' with pid #{pid} with a session id of {((AuthCore)Server.the_core).Clients[cid].session_id}...");
                break;
            }
            else
            {
                Logger.Syserr($"Client #{cid} attempted to enter a character of pid {pid} on a non existing map #{map} !!!");
                core.Clients[cid].tcp.Disconnect();
                return;
            }
        }
    }
Exemple #2
0
 public static void SendAlreadyConnectedPacket(int client)
 {
     using (Packet newPacket = new Packet((int)Packet.ServerPackets.alreadyConnected))
     {
         newPacket.Write(client);
         AuthCore.SendTCPData(client, newPacket);
     }
 }
Exemple #3
0
 public static void SendAuthFailed(int client)
 {
     using (Packet newPacket = new Packet((int)Packet.ServerPackets.authResult))
     {
         newPacket.Write(client);
         newPacket.Write(false);
         AuthCore.SendTCPData(client, newPacket);
     }
 }
Exemple #4
0
    public static void SendCharacterSelectionDataToClient(int client, CharacterSelectionEntry[] characters)
    {
        AuthCore core = (AuthCore)Server.the_core;

        using (Packet nPacket = new Packet((int)Packet.ServerPackets.charSelection))
        {
            nPacket.Write(client);
            nPacket.Write(core.Clients[client].session_id);
            for (int i = 0; i < Config.MaxCharactersInAccount; i++)
            {
                nPacket.Write(characters[i]);
            }

            AuthCore.SendTCPData(client, nPacket);
        }
    }
Exemple #5
0
    public override void Connect(TcpClient _socket)
    {
        configureSocket(_socket);
        stream.BeginRead(receivedBuff, 0, buffer_size, ReceiveCallback, null);

        /*
         *
         * A new client has connected to the authentication server
         * This is NOT an authentication request, its just a heartbeat
         * If we hear back a valid PONG response then we "allow" the client to request authentication
         */
        using (Packet newPacket = new Packet((int)Packet.ServerPackets.connectSucess))
        {
            newPacket.Write("Ping?");
            newPacket.Write(cid);
            AuthCore.SendTCPData(cid, newPacket);
        }
        try { Logger.Syslog($"Client #{client.cid} ({AuthCore.GetClientIP(cid)}) connected to the authentication server"); } catch { Logger.Syslog("A client connected to the authentication server but we couldn't retrieve it's ip address."); }
    }
Exemple #6
0
    public static void HandlePong(int fromClient, Packet packet)
    {
        int id      = packet.ReadInt();
        int pongLen = packet.ReadInt();

        byte[] pong = packet.ReadBytes(pongLen);
        if (id == fromClient)
        {
            byte[] hashed = Security.Hash("PONG" + fromClient, Security.GetSalt());
            if (Security.Verify(pong, hashed))
            {
                using (Packet newPacket = new Packet((int)Packet.ServerPackets.requestAuth))
                {
                    newPacket.Write(fromClient);
                    AuthCore.SendTCPData(fromClient, newPacket);
                }
            }
            else
            {
                Logger.Syserr($"Invalid client pong received, disconnecting client #{id}");
                Server.the_core.Clients[id].tcp.Disconnect();
            }
        }
    }