Example #1
0
        static string ReceiveUserData(Socket client)
        {
            string username, password, userChoice, userDataString;
            char   sp = ':';

            byte[]   userData = new byte[512];
            string[] spstring = new string[3];
            try
            {
                int receiveSize = client.Receive(userData);
                userDataString = Encoding.Default.GetString(userData).Substring(0, receiveSize);
                Console.WriteLine(userDataString);
                spstring = userDataString.Split(sp);
            }
            catch (Exception err)
            {
                Console.WriteLine("Error Message : " + err.Message);
            }

            if (spstring[0] == "SingUp")
            {
                userChoice = spstring[0];
                username   = spstring[1];
                password   = spstring[2];
                if (CheckUserNameSql(username) == true)
                {
                    String HelloTextBuf = "Username is Already in Use";
                    client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
                    username = "******";
                }
                else
                {
                    String HelloTextBuf = "Injoy Server";
                    client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
                    Console.WriteLine("Client In");

                    MySql           mySql      = new MySql();
                    MySqlConnection connection = mySql.ConnectSql();
                    mySql.InsertData(connection, username, password);
                    connection.Close();
                }
            }
            else if (spstring[0] == "SingIn")
            {
                userChoice = spstring[0];
                username   = spstring[1];
                password   = spstring[2];
                if (CheckPasswordSql(username, password) == false)
                {
                    String HelloTextBuf = "Username or Password Wrong Input";
                    client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
                    username = "******";
                }
                else
                {
                    String HelloTextBuf = "Injoy Server";
                    client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length)));
                    Console.WriteLine("Client In");
                }
            }
            else
            {
                Console.WriteLine("WhatSing? I don't know... May be UserOut");
                username = "******";
            }
            return(username);
        }
Example #2
0
        public static void LoadConfig()
        {
            using (XmlReader reader = XmlReader.Create(IO.Paths.DataFolder + "config.xml"))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "GamePort":
                            if (reader.Read())
                            {
                                GamePort = reader.ReadString().ToInt();
                            }
                            break;

                        case "DatabaseIP":
                            if (reader.Read())
                            {
                                DatabaseIP = reader.ReadString();
                            }
                            break;

                        case "DatabasePort":
                            if (reader.Read())
                            {
                                DatabasePort = reader.ReadString().ToInt();
                            }
                            break;

                        case "DatabaseUser":
                            if (reader.Read())
                            {
                                DatabaseUser = reader.ReadString();
                            }
                            break;

                        case "DatabasePassword":
                            if (reader.Read())
                            {
                                DatabasePassword = reader.ReadString();
                            }
                            break;
                        }
                    }
                }
            }


            using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data))
            {
                MySql database = dbConnection.Database;
                //load most recent news
                string query = "SELECT id, message " +
                               "FROM title WHERE title.id = 'GameName' OR title.id = 'MOTD' OR title.id = 'GameNameShort'";

                foreach (DataColumnCollection columnCollection in database.RetrieveRowsEnumerable(query))
                {
                    switch (columnCollection["id"].ValueString)
                    {
                    case "GameName":
                    {
                        GameName = columnCollection["message"].ValueString;
                    }
                    break;

                    case "GameNameShort":
                    {
                        GameNameShort = columnCollection["message"].ValueString;
                    }
                    break;

                    case "MOTD":
                    {
                        MOTD = columnCollection["message"].ValueString;
                    }
                    break;
                    }
                }

                query = "SELECT id, val " +
                        "FROM start_value " +
                        "WHERE start_value.id = 'Crossroads' " +
                        "OR start_value.id = 'NewCharForm' " +
                        "OR start_value.id = 'NewCharSpecies' " +
                        "OR start_value.id = 'StartMap' " +
                        "OR start_value.id = 'StartX' " +
                        "OR start_value.id = 'StartY'";

                foreach (DataColumnCollection columnCollection in database.RetrieveRowsEnumerable(query))
                {
                    switch (columnCollection["id"].ValueString)
                    {
                    case "Crossroads":
                    {
                        Crossroads = columnCollection["val"].ValueString.ToInt();
                    }
                    break;

                    case "NewCharForm":
                    {
                        NewCharForm = columnCollection["val"].ValueString.ToInt();
                    }
                    break;

                    case "NewCharSpecies":
                    {
                        NewCharSpecies = columnCollection["val"].ValueString.ToInt();
                    }
                    break;

                    case "StartMap":
                    {
                        StartMap = columnCollection["val"].ValueString.ToInt();
                    }
                    break;

                    case "StartX":
                    {
                        StartX = columnCollection["val"].ValueString.ToInt();
                    }
                    break;

                    case "StartY":
                    {
                        StartY = columnCollection["val"].ValueString.ToInt();
                    }
                    break;
                    }
                }
            }
        }