Beispiel #1
0
        public void TreatMessage(GameClient client, PacketType type, string[] messages)
        {
            switch (type)
            {
            case PacketType.COMND:
                if (client.status == GameClient.PlayerStatus.TERMINATED)
                {
                    break;
                }
                if (!CommandHandler.TreatCommand(client, messages[0]))
                {
                    client.Send(PacketType.OSMSG, "ERR:0");     // OSMSG:ERR:0 = La commande est introuvable
                }
                break;

            case PacketType.LOGIN:
                if (messages.Length < 2)
                {
                    return;
                }

                string tempUsername = messages[0];
                string tempPass     = messages[1];

                if (DatabaseLink.TryLogin(client, tempUsername, tempPass, out int homeId))
                {
                    client.username = tempUsername;
                    client.Send(PacketType.LOGRE, "0");     // Good account*/
                    var homeNode = computerManager.GetNodeById(homeId);
                    var ip       = "none";
                    if (homeNode != null)
                    {
                        ip = homeNode.ip;
                    }
                    client.Send(PacketType.START, ip);
                }
                else
                {
                    client.Send(PacketType.LOGRE, "1");
                    client.Disconnect();
                }
                break;

            case PacketType.DSCON:
                client.netDisconnect();
                break;
            }
        }
Beispiel #2
0
        public void TreatMessage(GameClient client, PacketType type, string[] messages)
        {
            switch (type)
            {
            case PacketType.COMND:
                //TODO fix cludge
                if (client.activeSession == null)
                {
                    client.ConnectTo(client.homeComputer);
                }
                if (client.status == GameClient.PlayerStatus.TERMINATED)
                {
                    break;
                }
                //TODO fixup
                // if (!CommandHandler.TreatCommand(client, messages[0]))
                //    client.Send(PacketType.OSMSG, "ERR:0"); // OSMSG:ERR:0 = La commande est introuvable
                client.activeSession.WriteInput(messages[0]);
                break;

            case PacketType.LOGIN:
                if (messages.Length < 2)
                {
                    return;
                }

                string tempUsername = messages[0];
                string tempPass     = messages[1];
                int    banExpiry;

                if (DatabaseLink.TryLogin(client, tempUsername, tempPass, out int homeId))
                {
                    client.username = tempUsername;
                    if (/*DatabaseLink.CheckUserBanStatus(client.username, out banExpiry)*/ false)
                    {
                        if (banExpiry == 0)
                        {
                            client.Send(PacketType.LOGRE, "2", "You have been banned permanently");
                            client.Disconnect();
                            break;
                        }
                        client.Send(PacketType.LOGRE, "2", $"You have been banned until {DateTimeOffset.FromUnixTimeSeconds(banExpiry).ToString()} UTC");
                        client.Disconnect();
                        break;
                    }
                    client.Send(PacketType.LOGRE, "0");     // Good account*/
                    var homeNode = computerManager.GetNodeById(homeId);
                    var ip       = "none";
                    if (homeNode != null)
                    {
                        ip = homeNode.ip;
                        client.homeComputer = homeNode;
                    }
                    client.permissions = DatabaseLink.GetUserPermissions()[client.username];
                    client.Send(PacketType.START, ip, DatabaseLink.GetUserNodes(client.username));
                }
                else
                {
                    client.Send(PacketType.LOGRE, "1");
                    client.Disconnect();
                }
                break;

            case PacketType.DSCON:
                client.netDisconnect();
                break;
            }
        }