示例#1
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();
        }
示例#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
        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;
                    }
                }
            }
        }
示例#4
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;
        }
        private void receiveMsg()
        {
            // What event happening, receive from server.
            while (state == GameState.none || state == GameState.map_warp)
            {
                try
                {
                    String responseMsg = network.Receive();
                    //Debug.WriteLine(responseMsg);
                    String[] line = responseMsg.Split(';');
                    for (int i = 0; i < line.Length; ++i)
                    {
                        String[] msg = line[i].Split(':');
                        // Get character info
                        if (msg[0].Equals("CHARINFOSELF") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 24)
                            {
                                String statusMsg = value[0];
                                if (statusMsg.Equals("OK"))
                                {
                                    // if status is OK
                                    CharacterInformation charInfo = new CharacterInformation(SelectedCharacterID, value[1] /*name*/,
                                                                                             Convert.ToInt16(value[2]) /*class*/, Convert.ToInt16(value[3]) /*level*/, Convert.ToInt32(value[4]) /*exp*/, Convert.ToInt32(value[5]) /*curexp*/, Convert.ToInt32(value[6]) /*gold*/,
                                                                                             Convert.ToInt32(value[7]) /*hp*/, Convert.ToInt32(value[8]) /*cur_hp*/, Convert.ToInt32(value[9]) /*sp*/, Convert.ToInt32(value[10]) /*cur_sp*/, Convert.ToInt32(value[11]) /*stpoint*/, Convert.ToInt32(value[12]) /*skpoint*/,
                                                                                             Convert.ToInt16(value[13]) /*str*/, Convert.ToInt16(value[14]) /*dex*/, Convert.ToInt16(value[15]) /*int*/, Convert.ToInt16(value[16]) /*hair*/,
                                                                                             Convert.ToInt16(value[17]) /*face*/, Convert.ToInt16(value[18]) /*curmap*/, Convert.ToSingle(value[19]) /*curmapx*/, Convert.ToSingle(value[20]) /*curmapy*/,
                                                                                             Convert.ToInt16(value[21]) /*savmap*/, Convert.ToSingle(value[22]) /*savmapx*/, Convert.ToSingle(value[23]) /*savmapy*/);
                                    game.getGuiGameAttribute().setValues(charInfo);
                                    game.getGuiGameEnvironment().setValues(charInfo);
                                    if (charInfo.getChar_curmap() != CurrentMapID)
                                    {
                                        CurrentMapID = charInfo.getChar_curmap();
                                        state        = GameState.map_warping;
                                    }
                                }
                            }
                        }
                        if (msg[0].Equals("NPCDIALOG") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 3)
                            {
                                int    npcid  = Convert.ToInt32(value[0]);
                                String txtmsg = value[1];
                                Dictionary <String, String> txtmenu = new Dictionary <String, String>();
                                String[] menus = value[2].Split(',');
                                for (int idx = 0; idx < menus.Length; ++idx)
                                {
                                    if ((idx + 1) % 2 == 0)
                                    {
                                        txtmenu.Add(menus[idx - 1], menus[idx]);
                                    }
                                }
                                game.getGuiGameNPC().setDialog(npcid, txtmsg, txtmenu);
                            }
                        }
                        // Walk target
                        if (msg[0].Equals("TARGETPOSITION") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 2)
                            {
                                float posx = Convert.ToSingle(value[0]);
                                float posy = Convert.ToSingle(value[1]);
                            }
                        }
                        // Action target
                        if (msg[0].Equals("TARGETPLAYERNODE") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 1)
                            {
                                int id = Convert.ToInt32(value[0]);
                            }
                        }
                        if (msg[0].Equals("TARGETMONSTERNODE") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 1)
                            {
                                int id = Convert.ToInt32(value[0]);
                            }
                        }
                        if (msg[0].Equals("TARGETNPCNODE") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 1)
                            {
                                int id = Convert.ToInt32(value[0]);
                            }
                        }
                        if (msg[0].Equals("TARGETWARPNODE") && msg.Length == 2)
                        {
                            // Split message value
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 1)
                            {
                                int id = Convert.ToInt32(value[0]);
                            }
                        }
                        // Requesting (Player, Monster, NPC, Warp, Item, ... etc)
                        // START REQUEST -> Player node
                        if (msg[0].Equals("LISTPLAYER") && msg.Length == 2)
                        {
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                if (SelectedCharacterID != Convert.ToInt32(value[j]) && !playersEntity.ContainsKey(value[j]))
                                {
                                    network.Send("NODEPLAYER:" + value[j] + ";");
                                }
                            }
                            foreach (String key in playersEntity.Keys)
                            {
                                if (!value.Contains(key))
                                {
                                    // May play any effect before remove...
                                    playersEntity.Remove(key);
                                    break;
                                }
                            }
                        }
                        if (msg[0].Equals("NODEPLAYER") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && !playersEntity.ContainsKey(value[0]))
                            {
                                playersEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager));
                            }
                        }
                        // END REQUEST -> Player node
                        // START REQUEST -> Monster node
                        if (msg[0].Equals("LISTMONSTER") && msg.Length == 2)
                        {
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                if (!monstersEntity.ContainsKey(value[j]))
                                {
                                    network.Send("NODEMONSTER:" + value[j] + ";");
                                }
                            }
                            foreach (String key in monstersEntity.Keys)
                            {
                                if (!value.Contains(key))
                                {
                                    // May play any effect before remove...
                                    monstersEntity.Remove(key);
                                    break;
                                }
                            }
                        }
                        if (msg[0].Equals("NODEMONSTER") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && !monstersEntity.ContainsKey(value[0]))
                            {
                                monstersEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager));
                            }
                        }
                        // END REQUEST -> Monster node
                        // START REQUEST -> NPC node
                        if (msg[0].Equals("LISTNPC") && msg.Length == 2)
                        {
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                if (!npcsEntity.ContainsKey(value[j]))
                                {
                                    network.Send("NODENPC:" + value[j] + ";");
                                }
                            }
                            foreach (String key in npcsEntity.Keys)
                            {
                                if (!value.Contains(key))
                                {
                                    // May play any effect before remove...
                                    npcsEntity.Remove(key);
                                    break;
                                }
                            }
                        }
                        if (msg[0].Equals("NODENPC") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && !npcsEntity.ContainsKey(value[0]))
                            {
                                npcsEntity.Add(value[0], new UnitEntity(Convert.ToInt32(value[0]), value[1], classConfigs[Convert.ToInt16(value[2])], Convert.ToInt32(value[3]), Convert.ToInt32(value[4]), Convert.ToInt32(value[5]), Convert.ToInt32(value[6]), game, content, graphics, spriteBatch, entityNameFont, entityDamageFont, whiteRect, modelBank, itemBank, audioSystem, particleManager));
                            }
                        }
                        // END REQUEST -> NPC node
                        // START REQUEST -> Warp node
                        if (msg[0].Equals("LISTWARP") && msg.Length == 2)
                        {
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                if (!warpsEntity.ContainsKey(value[j]))
                                {
                                    network.Send("NODEWARP:" + value[j] + ";");
                                }
                            }
                            foreach (String key in warpsEntity.Keys)
                            {
                                if (!value.Contains(key))
                                {
                                    // May play any effect before remove...
                                    warpsEntity.Remove(key);
                                    break;
                                }
                            }
                        }
                        if (msg[0].Equals("NODEWARP") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 3 && !warpsEntity.ContainsKey(value[0]))
                            {
                                warpsEntity.Add(value[0], new WarpEntity(Convert.ToInt32(value[0]), Convert.ToSingle(value[1]), Convert.ToSingle(value[2]), content));
                            }
                        }
                        // END REQUEST -> Warp node
                        // START REQUEST -> Item node
                        if (msg[0].Equals("LISTITEM") && msg.Length == 2)
                        {
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                if (!itemsEntity.ContainsKey(value[j]))
                                {
                                    network.Send("NODEITEM:" + value[j] + ";");
                                }
                            }
                            foreach (String key in itemsEntity.Keys)
                            {
                                if (!value.Contains(key))
                                {
                                    // May play any effect before remove...
                                    itemsEntity.Remove(key);
                                    break;
                                }
                            }
                        }
                        if (msg[0].Equals("NODEITEM") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 3 && !itemsEntity.ContainsKey(value[0]))
                            {
                                itemsEntity.Add(value[0], new ItemEntity(Convert.ToInt32(value[0]), Convert.ToInt16(value[1]), content, graphics, spriteBatch, entityNameFont, whiteRect, itemBank));
                            }
                        }
                        // END REQUEST -> Item node
                        // UPDATE NODE
                        if (msg[0].Equals("NODEPLAYERUPDATE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 9)
                            {
                                UnitEntity ent = null;
                                if (SelectedCharacterID == Convert.ToInt32(value[0]))
                                {
                                    ent = playerEntity;
                                }
                                else
                                {
                                    playersEntity.TryGetValue(value[0], out ent);
                                }
                                if (ent != null)
                                {
                                    float   posx = Convert.ToSingle(value[1]);
                                    float   posy = Convert.ToSingle(value[2]);
                                    Vector3 pos  = new Vector3(posx, 0, posy);
                                    if (ent.Equals(playerEntity))
                                    {
                                        camera.target = pos;
                                    }
                                    ent.setPosition(pos);
                                    ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3]));
                                    ent.curHP = Convert.ToInt32(value[4]);
                                    ent.maxHP = Convert.ToInt32(value[5]);
                                    ent.curSP = Convert.ToInt32(value[6]);
                                    ent.maxSP = Convert.ToInt32(value[7]);
                                    float roty = Convert.ToSingle(value[8]);
                                    ent.setRotation(new Vector3(0, roty, 0));
                                }
                            }
                        }
                        if (msg[0].Equals("NODEMONSTERUPDATE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 9)
                            {
                                UnitEntity ent = null;
                                if (monstersEntity.TryGetValue(value[0], out ent))
                                {
                                    float posx = Convert.ToSingle(value[1]);
                                    float posy = Convert.ToSingle(value[2]);
                                    ent.setPosition(new Vector3(posx, 0, posy));
                                    ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3]));
                                    ent.curHP = Convert.ToInt32(value[4]);
                                    ent.maxHP = Convert.ToInt32(value[5]);
                                    ent.curSP = Convert.ToInt32(value[6]);
                                    ent.maxSP = Convert.ToInt32(value[7]);
                                    float roty = Convert.ToSingle(value[8]);
                                    ent.setRotation(new Vector3(0, roty, 0));
                                }
                            }
                        }
                        if (msg[0].Equals("NODENPCUPDATE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 9)
                            {
                                UnitEntity ent = null;
                                if (npcsEntity.TryGetValue(value[0], out ent))
                                {
                                    float posx = Convert.ToSingle(value[1]);
                                    float posy = Convert.ToSingle(value[2]);
                                    ent.setPosition(new Vector3(posx, 0, posy));
                                    ent.currentState(GameState.anim_anim + 1 + Convert.ToInt32(value[3]));
                                    ent.curHP = Convert.ToInt32(value[4]);
                                    ent.maxHP = Convert.ToInt32(value[5]);
                                    ent.curSP = Convert.ToInt32(value[6]);
                                    ent.maxSP = Convert.ToInt32(value[7]);
                                    float roty = Convert.ToSingle(value[8]);
                                    ent.setRotation(new Vector3(0, roty, 0));
                                }
                            }
                        }
                        // Damage
                        if (msg[0].Equals("PLAYERNODEDAMAGE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 2 && SelectedCharacterID > 0)
                            {
                                UnitEntity ent = null;
                                if (SelectedCharacterID == Convert.ToInt32(value[0]))
                                {
                                    ent = playerEntity;
                                }
                                else
                                {
                                    playersEntity.TryGetValue(value[0], out ent);
                                }
                                if (ent != null)
                                {
                                    // Show damage
                                    ent.recieveDamage(Convert.ToInt32(value[1]));
                                }
                            }
                        }
                        if (msg[0].Equals("MONSTERNODEDAMAGE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 2 && SelectedCharacterID > 0)
                            {
                                UnitEntity ent = null;
                                if (monstersEntity.TryGetValue(value[0], out ent))
                                {
                                    // Show damage
                                    ent.recieveDamage(Convert.ToInt32(value[1]));
                                }
                            }
                        }
                        if (msg[0].Equals("NPCNODEDAMAGE") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 2)
                            {
                                UnitEntity ent = null;
                                if (npcsEntity.TryGetValue(value[0], out ent))
                                {
                                    // Show damage
                                    ent.recieveDamage(Convert.ToInt32(value[1]));
                                }
                            }
                        }

                        // Inventory list
                        if (msg[0].Equals("INVENTORYINFO") && msg.Length == 2)
                        {
                            GUIGameInventory inven  = game.getGuiGameInventory();
                            GUIGameEquipment equipm = game.getGuiGameEquipment();
                            // Split message value
                            List <String> value = new List <String>(msg[1].Split(' '));
                            for (int j = 0; j < value.Count; ++j)
                            {
                                String[] itemData = value[j].Split('&');
                                if (itemData.Length == 10 && SelectedCharacterID > 0)
                                {
                                    int   inventoryidx = Convert.ToInt32(itemData[0]);
                                    int   itemid       = Convert.ToInt32(itemData[1]);
                                    short amount       = Convert.ToInt16(itemData[2]);
                                    short equip        = Convert.ToInt16(itemData[3]);
                                    short refine       = Convert.ToInt16(itemData[4]);
                                    int   attributeid  = Convert.ToInt32(itemData[5]);
                                    int   slot1        = Convert.ToInt32(itemData[6]);
                                    int   slot2        = Convert.ToInt32(itemData[7]);
                                    int   slot3        = Convert.ToInt32(itemData[8]);
                                    int   slot4        = Convert.ToInt32(itemData[9]);
                                    if (equip != 0)
                                    {
                                        InventoryItemData newItemData = new InventoryItemData(itemid, amount, refine, attributeid, slot1, slot2, slot3, slot4);

                                        if (!equipm.isSameItemData(equip, newItemData))
                                        {
                                            equipm.setItemData(equip, newItemData);
                                        }
                                    }
                                    else
                                    {
                                        InventoryItemData newItemData = new InventoryItemData(itemid, amount, refine, attributeid, slot1, slot2, slot3, slot4);

                                        if (!inven.isSameItemData(inventoryidx, newItemData))
                                        {
                                            inven.setItemData(inventoryidx, newItemData);
                                        }
                                    }
                                }
                            }
                        }
                        // Equipment
                        if (msg[0].Equals("NODEPLAYEREQUIPMENT") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && SelectedCharacterID > 0)
                            {
                                int id             = Convert.ToInt32(value[0]);
                                int itemid_head    = Convert.ToInt32(value[1]);
                                int itemid_body    = Convert.ToInt32(value[2]);
                                int itemid_hand    = Convert.ToInt32(value[3]);
                                int itemid_foot    = Convert.ToInt32(value[4]);
                                int itemid_weaponR = Convert.ToInt32(value[5]);
                                int itemid_weaponL = Convert.ToInt32(value[6]);
                                if (id == SelectedCharacterID)
                                {
                                    playerEntity.setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL);
                                }
                                else
                                {
                                    if (playersEntity.ContainsKey("" + id))
                                    {
                                        playersEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL);
                                    }
                                }
                            }
                        }
                        if (msg[0].Equals("NODEMONSTEREQUIPMENT") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && SelectedCharacterID > 0)
                            {
                                int id             = Convert.ToInt32(value[0]);
                                int itemid_head    = Convert.ToInt32(value[1]);
                                int itemid_body    = Convert.ToInt32(value[2]);
                                int itemid_hand    = Convert.ToInt32(value[3]);
                                int itemid_foot    = Convert.ToInt32(value[4]);
                                int itemid_weaponR = Convert.ToInt32(value[5]);
                                int itemid_weaponL = Convert.ToInt32(value[6]);
                                if (monstersEntity.ContainsKey("" + id))
                                {
                                    monstersEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL);
                                }
                            }
                        }
                        if (msg[0].Equals("NODENPCEQUIPMENT") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length == 7 && SelectedCharacterID > 0)
                            {
                                int id             = Convert.ToInt32(value[0]);
                                int itemid_head    = Convert.ToInt32(value[1]);
                                int itemid_body    = Convert.ToInt32(value[2]);
                                int itemid_hand    = Convert.ToInt32(value[3]);
                                int itemid_foot    = Convert.ToInt32(value[4]);
                                int itemid_weaponR = Convert.ToInt32(value[5]);
                                int itemid_weaponL = Convert.ToInt32(value[6]);
                                if (npcsEntity.ContainsKey("" + id))
                                {
                                    npcsEntity["" + id].setEquipmentItemID(itemid_head, itemid_body, itemid_hand, itemid_foot, itemid_weaponR, itemid_weaponL);
                                }
                            }
                        }
                        if (msg[0].Equals("CHAT") && msg.Length == 2)
                        {
                            String[] value = msg[1].Split(' ');
                            if (value.Length > 0 && SelectedCharacterID > 0)
                            {
                                byte   msgType    = Convert.ToByte(value[0]);
                                String charid     = value[1];
                                String recMessage = "";
                                String name       = "";
                                switch (msgType)
                                {
                                case 0:
                                    if (charid.Equals("" + playerEntity.getID()))
                                    {
                                        name = playerEntity.getName();
                                    }
                                    else
                                    {
                                        name = playersEntity[charid].getName();
                                    }
                                    for (int index = 2; index < value.Length; ++index)
                                    {
                                        recMessage += (value[index] + " ");
                                    }
                                    game.getGuiGameChat().InsertMessage(msgType, name, recMessage);
                                    break;

                                case 1:
                                    if (charid.Equals("" + playerEntity.getID()))
                                    {
                                        name = playerEntity.getName();
                                    }
                                    else
                                    {
                                        name = playersEntity[charid].getName();
                                    }
                                    recMessage += (" [" + name + "]");
                                    for (int index = 2; index < value.Length; ++index)
                                    {
                                        recMessage += (value[index] + " ");
                                    }
                                    game.getGuiGameChat().InsertMessage(msgType, name, recMessage);
                                    break;

                                case 2:
                                    break;

                                case 3:
                                    break;
                                }
                            }
                        }
                    } // For scope
                }     // Try scope
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
                // Sleep 50ms avoiding 100% CPU
                Thread.Sleep(50);
            }
        }