void upBtn_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     if (sender.Equals(this.strBtn) || sender.Equals(this.dexBtn) || sender.Equals(this.intBtn))
     {
         if (sender.Equals(this.strBtn))
         {
             // Send to server that player up str
             // Send chat message
             if (network.isConnected())
             {
                 network.Send("ADDSTR:1;");
             }
         }
         if (sender.Equals(this.dexBtn))
         {
             // Send to server that player up dex
             // Send chat message
             if (network.isConnected())
             {
                 network.Send("ADDDEX:1;");
             }
         }
         if (sender.Equals(this.intBtn))
         {
             // Send to server that player up int
             // Send chat message
             if (network.isConnected())
             {
                 network.Send("ADDINT:1;");
             }
         }
     }
 }
Example #2
0
        void item_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            int equipIdx = Convert.ToInt32(((ImageBox)sender).Name);

            if (guiGameInventory != null)
            {
                if (guiGameInventory.getSelectedItemIndex() < 0)
                {
                    if (selectedItemIndex >= 0)
                    {
                        if (selectedItemIndex == equipIdx)
                        {
                            ((ImageBox)sender).Image = selectedItemTexture;
                            selectedItemTexture      = null;
                            selectedItemIndex        = -1;
                        }
                    }
                    else
                    {
                        selectedItemTexture      = ((ImageBox)sender).Image;
                        ((ImageBox)sender).Image = nullTexture;
                        selectedItemIndex        = equipIdx;
                    }
                }
                else
                {
                    // Use selected item
                    if (network.isConnected())
                    {
                        network.Send("INVENTORYUSE:" + guiGameInventory.getSelectedItemIndex() + ";");
                        guiGameInventory.clearSelectedItem();
                    }
                }
            }
        }
Example #3
0
        void item_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            // Drag Item
            int itemIdx = Convert.ToInt32(((ImageBox)sender).Name);

            if (guiGameEquipment != null)
            {
                if (guiGameEquipment.getSelectedItemIndex() < 0)
                {
                    if (selectedItemIndex >= 0)
                    {
                        if (selectedItemIndex == itemIdx)
                        {
                            ((ImageBox)sender).Image = selectedItemTexture;
                            selectedItemTexture      = null;
                            selectedItemIndex        = -1;
                        }
                        else
                        {
                            if (network.isConnected())
                            {
                                network.Send("INVENTORYDRAG:" + selectedItemIndex + " " + itemIdx + ";");
                                selectedItemTexture = null;
                                selectedItemIndex   = -1;
                            }
                        }
                    }
                    else
                    {
                        selectedItemTexture      = ((ImageBox)sender).Image;
                        ((ImageBox)sender).Image = nullTexture;
                        selectedItemIndex        = itemIdx;
                    }
                }
                else
                {
                    // Unequip
                    if (network.isConnected())
                    {
                        network.Send("UNWEARDRAGTO:" + guiGameEquipment.getSelectedItemIndex() + " " + itemIdx + ";");
                        guiGameEquipment.clearSelectedItem();
                    }
                }
            }
        }
 void btn_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     if (txtmenu.ContainsKey(menu.ItemIndex))
     {
         // Send chat message
         if (network.isConnected())
         {
             network.Send("NPCDIALOG:" + npcid + " " + txtmenu[menu.ItemIndex] + ";");
         }
         this.Visible = false;
     }
 }
Example #5
0
        void GameMain_Exiting(object sender, System.EventArgs e)
        {
            if (cue != null && cue.IsPlaying)
            {
                cue.Stop(AudioStopOptions.Immediate);
            }
            while (gameHandler != null && gameHandler.receiveThread != null && gameHandler.receiveThread.IsAlive)
            {
                if (gameHandler.currentState() == GameState.none || gameHandler.currentState() == GameState.map_warp)
                {
                    gameHandler.currentState(GameState.map_backtologin);
                }
                gameHandler.receiveThread.Abort();
            }
            long startExit = DateTime.Now.Ticks;

            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();
        }
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        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();
                }
            }
        }
Example #7
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;
                    }
                }
            }
        }