コード例 #1
0
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        private void SendMessage(EventArgs x)
        {
            KeyEventArgs     k = new KeyEventArgs();
            GamePadEventArgs g = new GamePadEventArgs(PlayerIndex.One);

            if (x is KeyEventArgs)
            {
                k = x as KeyEventArgs;
            }
            else if (x is GamePadEventArgs)
            {
                g = x as GamePadEventArgs;
            }

            ConsoleChannel ch = console.Channels[cmbMain.ItemIndex];

            if (ch != null)
            {
                txtMain.TextColor = ch.Color;

                string message = txtMain.Text;
                if ((k.Key == Microsoft.Xna.Framework.Input.Keys.Enter || g.Button == GamePadActions.Press) && message != null && message != "")
                {
                    x.Handled = true;
                    // Send chat message
                    if (network.isConnected())
                    {
                        string chatMsg = txtMain.Text;
                        chatMsg = chatMsg.Replace("'", "'39'");
                        chatMsg = chatMsg.Replace(" ", "'32'");
                        chatMsg = chatMsg.Replace(":", "'58'");
                        chatMsg = chatMsg.Replace(";", "'59'");
                        network.Send("CHAT:" + cmbMain.ItemIndex + " " + chatMsg + ";");
                    }
                    txtMain.Text = "";
                    ClientArea.Invalidate();
                }
            }
        }
コード例 #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;
        }
コード例 #3
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;
        }
コード例 #4
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;
                    }
                }
            }
        }
コード例 #5
0
 void rebornBtn_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     this.Visible = false;
     network.Send("REBORN:0;");
 }
コード例 #6
0
 public void ProcessMouse()
 {
     try
     {
         prevMouseState    = currentMouseState;
         currentMouseState = Mouse.GetState();
         Vector3 Cursor3D    = camera.getCursor3D();
         Ray     Cursor3DRay = camera.getCursor3DRay();
         foreach (UnitEntity ent in monstersEntity.Values)
         {
             if (ent != targetNode)
             {
                 if (ent != null)
                 {
                     ent.drawHP = false;
                 }
             }
             if (ent != null && ent.RayIntersectsModel(Cursor3DRay))
             {
                 ent.drawName = true;
                 if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                 {
                     targetPos  = normalTargetPos;
                     targetNode = ent;
                     ent.drawHP = true;
                     network.Send("TARGETMONSTERNODE:" + ent.getID() + ";");
                     return;
                 }
             }
             else
             {
                 if (ent != null)
                 {
                     ent.drawName = false;
                 }
             }
         }
         foreach (UnitEntity ent in npcsEntity.Values)
         {
             if (ent != null && ent.RayIntersectsModel(Cursor3DRay))
             {
                 ent.drawName = true;
                 if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                 {
                     targetPos  = normalTargetPos;
                     targetNode = ent;
                     network.Send("TARGETNPCNODE:" + ent.getID() + ";");
                     return;
                 }
             }
             else
             {
                 if (ent != null)
                 {
                     ent.drawName = false;
                 }
             }
         }
         foreach (UnitEntity ent in playersEntity.Values)
         {
             if (ent != null && ent.RayIntersectsModel(Cursor3DRay))
             {
                 ent.drawName = true;
                 if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                 {
                     targetPos  = normalTargetPos;
                     targetNode = ent;
                     network.Send("TARGETPLAYERNODE:" + ent.getID() + ";");
                     return;
                 }
             }
             else
             {
                 if (ent != null)
                 {
                     ent.drawName = false;
                 }
             }
         }
         foreach (WarpEntity ent in warpsEntity.Values)
         {
             if (ent != null && ent.RayIntersectsModel(Cursor3DRay))
             {
                 if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                 {
                     targetNode = null;
                     targetPos  = ent.getPosition();
                     network.Send("TARGETWARPNODE:" + ent.getID() + ";");
                     return;
                 }
             }
         }
         foreach (ItemEntity ent in itemsEntity.Values)
         {
             if (ent != null && ent.RayIntersectsModel(Cursor3DRay))
             {
                 if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                 {
                     targetNode = null;
                     targetPos  = ent.getPosition();
                     network.Send("TARGETITEMNODE:" + ent.getID() + ";");
                     return;
                 }
             }
         }
         if (Cursor3D != null)
         {
             if (prevMouseState != null && prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
             {
                 targetNode = null;
                 targetPos  = new Vector3(Cursor3D.X, 0, Cursor3D.Z);
                 network.Send("TARGETPOSITION:" + Cursor3D.X + " " + Cursor3D.Z + ";");
                 return;
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.StackTrace);
     }
 }