示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var userId = 0;
            TextBox IDtextbox = (TextBox)IDTextbox;
            if (!Int32.TryParse(IDtextbox.Text, out userId))
            {
                NotifLabel.Text = "Please insert valid ID.";
                IDTextbox.Clear();
            }
            else
            {
                Regex ipParser = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
                TextBox IPtextbox = (TextBox)IPTextbox;
                MatchCollection result = ipParser.Matches(IPtextbox.Text);
                if (!(result.Count == 1))
                {
                    IPTextbox.Clear();
                    NotifLabel.Text = "Please insert valid IP.";
                    IPTextbox.Clear();

                }
                else {
                    var match = result[0];
                    NotifLabel.Text = "Connecting from user " + userId + " to " + match.Value;
                    if (NotifLabel.CanFocus)
                    {
                        NotifLabel.Focus();
                    }
                    //TODO: LoginService
                    SQLiteConnection cnnect = new SQLiteConnection("Data Source=" + dbname + ";Version=3;");
                    cnnect.Open();
                    SQLiteCommand command = new SQLiteCommand();
                    command.Connection = cnnect;
                    command.CommandText = @"INSERT INTO [players]([id], [xcoordinate], [ycoordinate], [size]) "
                                + "VALUES (" + userId + ", 335, 300, 40);";
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                    cnnect.Close();
                    gclient = new GameClient(IPTextbox.Text, this){ Id = userId, IP = IPTextbox.Text };
                }
            }
        }