Esempio n. 1
0
        public void load()
        {
            char_class.Items.Clear();
            classIdPair.Clear();
            // Load character data
            createButton.Enabled = false;
            backButton.Enabled   = false;
            game.messageDialog.setTitle("");
            game.messageDialog.setMessage("Please wait...");
            game.messageDialog.Visible            = true;
            game.messageDialog.CloseButtonVisible = false;
            String responseMsg = "";

            try
            {
                // Try connect to server
                //if (!network.isConnected())
                //    network.Connect("127.0.0.1", 5000);
                // Send login message
                network.Send("CHARCREATEABLE:" + LoggedUserID + ";"); // Get character from index
                // Receive message
                while (responseMsg.Length <= 0)
                {
                    responseMsg = network.Receive();
                }
            }
            catch (Exception e)
            {
                // Has any error come here
                Debug.WriteLine(e.ToString());
                game.messageDialog.setTitle("ERROR!!");
                game.messageDialog.setMessage("Can't connect to server.");
                game.messageDialog.Visible            = true;
                game.messageDialog.CloseButtonVisible = true;
                state = GameState.none;
            }
            // Split message from end of line
            String[] line = responseMsg.Split(';');
            for (int i = 0; i < line.Length; ++i)
            {
                // If has message
                // CHARCREATEAVAILABLE:{ID1} {ID2} {ID3} ... {ID4};
                String[] msg = line[i].Split(':');
                if (msg[0].Equals("CHARCREATEABLE") && msg.Length == 2)
                {
                    // Split message value
                    List <String> value = new List <String>(msg[1].Split(' '));
                    for (int j = 0; j < value.Count; ++j)
                    {
                        short           classid = Convert.ToInt16(value[j]);
                        GameClassConfig cfg     = null;
                        if (classConfigs.TryGetValue(classid, out cfg))
                        {
                            char_class.Items.Add(cfg.name);
                            classIdPair.Add(classid);
                        }
                    }
                }
            }
            char_class.ItemIndex = 0;
            game.hideMessageDialog();
            createButton.Enabled = true;
            backButton.Enabled   = true;
        }
Esempio n. 2
0
        public void load()
        {
            // Load character data
            createButton.Enabled = false;
            startButton.Enabled  = false;
            game.messageDialog.setTitle("");
            game.messageDialog.setMessage("Please wait...");
            game.messageDialog.Visible            = true;
            game.messageDialog.CloseButtonVisible = false;
            Boolean end = false;

            for (int i = 0; i < game.maxchar; ++i)
            {
                String responseMsg = "";
                String statusMsg   = "";
                try
                {
                    // Try connect to server
                    //if (!network.isConnected())
                    //    network.Connect("127.0.0.1", 5000);
                    // Send login message
                    network.Send("CHARGET:" + LoggedUserID + " " + i + ";"); // Get character from index
                    // Receive message
                    while (responseMsg.Length <= 0)
                    {
                        responseMsg = network.Receive();
                    }
                }
                catch (Exception e)
                {
                    // Has any error come here
                    Debug.WriteLine(e.ToString());
                    game.messageDialog.setTitle("ERROR!!");
                    game.messageDialog.setMessage("Can't connect to server.");
                    game.messageDialog.Visible            = true;
                    game.messageDialog.CloseButtonVisible = true;
                    state = GameState.none;
                }
                // Split message from end of line
                String[] line = responseMsg.Split(';');
                for (int j = 0; j < line.Length; ++j)
                {
                    // If has message
                    // Split message name(CHARGET) and value({STATUS}|{CHARID})
                    // CHARGET:{STATUS}|{CHARID};
                    String[] msg = line[j].Split(':');
                    if (msg[0].Equals("CHARGET") && msg.Length == 2)
                    {
                        // Split message value
                        String[] value = msg[1].Split(' ');
                        if (value.Length == 2)
                        {
                            statusMsg = value[0];
                        }
                        if (statusMsg.Equals("OK"))
                        {
                            // if status is OK
                            try
                            {
                                // If character found show panel
                                CharacterInformation chara = getCharInfo(Convert.ToInt32(value[1]));
                                if (chara != null)
                                {
                                    if (!charInfo.ContainsKey(chara.getCharid()))
                                    {
                                        charInfo.Add(chara.getCharid(), chara);
                                        listId.Add(i, chara.getCharid());
                                        character_name[i].Text            = ("Name: " + charInfo[listId[i]].getChar_name());
                                        character_level[i].Text           = ("LV: " + charInfo[listId[i]].getChar_level());
                                        character_selectButton[i].Enabled = true;
                                        character_deleteButton[i].Enabled = true;
                                        character_panel[i].Visible        = true;
                                        state = GameState.none;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                // Has any error come here
                                Debug.WriteLine(e.ToString());
                                game.messageDialog.setTitle("ERROR!!");
                                game.messageDialog.setMessage("There has something error.");
                                game.messageDialog.Visible            = true;
                                game.messageDialog.CloseButtonVisible = true;
                                state = GameState.none;
                            }
                            break;
                        }
                        else
                        {
                            // if status isn't OK
                            state = GameState.none;
                            end   = true;
                            break;
                        }
                    }
                }
                // If Readed all character data
                if (end)
                {
                    break;
                }
            }
            game.hideMessageDialog();
            createButton.Enabled = true;
            startButton.Enabled  = true;
        }
Esempio n. 3
0
        private void loginThread()
        {
            String responseMsg = "";
            String statusMsg   = "";
            String idMsg       = "";

            try
            {
                // Try connect to server
                if (!network.isConnected())
                {
                    network.Connect(serverConfig.getIP(), serverConfig.getPort());
                }
                // Starting ping...
                // Send login message
                network.Send("LOGIN:"******" " + password.Text + ";");
                // Receive message
                while (responseMsg.Length <= 0)
                {
                    responseMsg = network.Receive();
                }
            }
            catch (Exception e)
            {
                // Has any error come here
                Debug.WriteLine(e.ToString());
                username.Enabled    = true;
                password.Enabled    = true;
                loginButton.Enabled = true;
                game.messageDialog.setTitle("ERROR!!");
                game.messageDialog.setMessage("Can't connect to server.");
                game.messageDialog.Visible            = true;
                game.messageDialog.CloseButtonVisible = true;
                LoggedUserID = 0;
                state        = GameState.none;
            }
            // Split message from end of line
            String[] line = responseMsg.Split(';');
            for (int i = 0; i < line.Length; ++i)
            {
                // If has message
                // Split message name(LOGIN) and value({STATUS}|{LOGINID})
                // LOGIN:{STATUS}|{LOGINID};
                String[] msg = line[i].Split(':');
                if (msg[0].Equals("LOGIN") && msg.Length == 2)
                {
                    // Split message value
                    String[] value = msg[1].Split(' ');
                    if (value.Length == 2)
                    {
                        statusMsg = value[0];
                        idMsg     = value[1];
                    }
                    if (statusMsg.Equals("OK") && !idMsg.Equals("0"))
                    {
                        // if status is OK
                        try
                        {
                            username.Enabled    = true;
                            password.Enabled    = true;
                            loginButton.Enabled = true;
                            game.hideMessageDialog();
                            LoggedUserID = Convert.ToInt32(idMsg);
                            state        = GameState.login_loggedin;
                        }
                        catch (Exception e)
                        {
                            // Has any error come here
                            // I was expect that NumberFormatException can occur
                            Debug.WriteLine(e.ToString());
                            username.Enabled    = true;
                            password.Enabled    = true;
                            loginButton.Enabled = true;
                            game.messageDialog.setTitle("ERROR!!");
                            game.messageDialog.setMessage("Wrong username or password.");
                            game.messageDialog.Visible            = true;
                            game.messageDialog.CloseButtonVisible = true;
                            LoggedUserID = 0;
                            state        = GameState.none;
                        }
                    }
                    else
                    {
                        // if status isn't OK
                        network.Send("LOGOUT:0;");
                        bool isLoggedOut = false;
                        while (!isLoggedOut && network.isConnected())
                        {
                            String responseLogoutMsg = "";
                            while (responseLogoutMsg.Length <= 0)
                            {
                                responseLogoutMsg = network.Receive();
                            }
                            String[] LogoutLine = responseLogoutMsg.Split(';');
                            for (int l = 0; l < LogoutLine.Length; ++l)
                            {
                                String[] LogoutMsg = LogoutLine[l].Split(':');
                                if (LogoutMsg[0].Equals("LOGOUT") && LogoutMsg.Length == 2)
                                {
                                    isLoggedOut = true;
                                    break;
                                }
                            }
                        }
                        network.Close();
                        username.Enabled    = true;
                        password.Enabled    = true;
                        loginButton.Enabled = true;
                        if (idMsg.Equals(0))
                        {
                            game.messageDialog.setTitle("ERROR!!");
                            game.messageDialog.setMessage("Wrong username or password.");
                            game.messageDialog.Visible            = true;
                            game.messageDialog.CloseButtonVisible = true;
                        }
                        else
                        {
                            game.messageDialog.setTitle("ERROR!!");
                            game.messageDialog.setMessage("This user is already login.");
                            game.messageDialog.Visible            = true;
                            game.messageDialog.CloseButtonVisible = true;
                        }
                        LoggedUserID = 0;
                        break;
                    }
                }
            }
        }