Exemplo n.º 1
0
        // interface initialize
        private void GetActorData()
        {
            Mainform.Invoke(new MethodInvoker(
                                delegate()
            {
                // # interface initialze #
                // chat form
                Form_Chat = new Forms.Chatting();
                Form_Chat.Show();
                Form_Chat.Location = new System.Drawing.Point(Mainform.Location.X + 3, Mainform.Location.Y + Mainform.Height - 131);

                // name tag
                nametag = new Forms.NameTag(Properties.Settings.Default.UserId);
                nametag.Show();


                // # character initialze #
                // create an actor
                Actor          = new GameObject(Content.Load <Texture2D>("Sprites\\" + Properties.Settings.Default.Actor_sprite));
                Actor.position = new Vector2(Properties.Settings.Default.Actor_x, Properties.Settings.Default.Actor_y);

                // get map informations
                MapChanged(Properties.Settings.Default.MapId, Properties.Settings.Default.Actor_x, Properties.Settings.Default.Actor_y);
            }
                                )
                            );
        }
Exemplo n.º 2
0
        // Packet Receive
        private void Receive_Completed(object sender, SocketAsyncEventArgs e)
        {
            Socket ClientSocket = (Socket)sender;

            if (ClientSocket.Connected && e.BytesTransferred > 0)
            {
                byte[] szData2 = e.Buffer;
                e.SetBuffer(szData2, 0, szData2.Length);
                string sDatas = Encoding.Unicode.GetString(szData2);
                String sData  = sDatas;

                // # Packet Handling #
                try
                {
                    string[] co      = { "&%*^%" };
                    string[] dcodata = sData.Split(co, StringSplitOptions.RemoveEmptyEntries);

                    sData = dcodata[0];
                    string pkcode = dcodata[1];

                    #region Login

                    if (pkcode.Equals("UD"))
                    {
                        string[] spear = { "," };
                        string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                        // # 계정 데이터 획득 #
                        Properties.Settings.Default.UserId       = words[0];
                        Properties.Settings.Default.MapId        = Int32.Parse(words[1]);
                        Properties.Settings.Default.Actor_x      = Int32.Parse(words[2]);
                        Properties.Settings.Default.Actor_y      = Int32.Parse(words[3]);
                        Properties.Settings.Default.Actor_sprite = words[4];

                        Properties.Settings.Default.LoginCheck = true;

                        // get interface and user data
                        GetActorData();

                        // exit login form
                        Mainform.Invoke(new MethodInvoker(
                                            delegate()
                        {
                            Form_Login.Dispose();
                        }
                                            )
                                        );
                    }
                    else if (pkcode.Equals("LoginFail"))
                    {
                        ShowMessage("비밀번호를 확인해 주세요!");
                    }
                    else if (pkcode.Equals("LoginAlready"))
                    {
                        ShowMessage("현재 접속중인 계정입니다.");
                    }

                    #endregion

                    #region [Game Systems]

                    if (Properties.Settings.Default.LoginCheck)
                    {
                        // receive all chat

                        #region Chat systems

                        if (pkcode.Equals("AllChat"))
                        {
                            // update chat
                            Mainform.Invoke(new MethodInvoker(
                                                delegate()
                            {
                                // auto initializ chat data
                                try
                                {
                                    if (Form_Chat.panel1.VerticalScroll.Maximum >= 17000) // overall 17,000 - renew
                                    {
                                        Form_Chat.Dispose();
                                        Form_Chat = new Forms.Chatting();
                                        Form_Chat.Show();
                                        Form_Chat.Location = new System.Drawing.Point(Mainform.Location.X + 3, Mainform.Location.Y + Mainform.Height - 131);
                                    }
                                }
                                catch { }

                                // show up a new chat
                                Chatwrite(sData);

                                // receive other player's a new ballon
                                string[] spear = { " : " };
                                string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                                if (!words[0].Equals(Properties.Settings.Default.UserId))
                                {
                                    for (int i = 0; i < Users.Count; i++)
                                    {
                                        if (Users[i].username.Equals(words[0]))
                                        {
                                            if (Users[i].chatballon != null)
                                            {
                                                Users[i].chatballon.Dispose();
                                            }

                                            Users[i].chatballon = new Forms.ChatBallon(sData);
                                            Users[i].chatballon.Show();
                                        }
                                    }
                                }
                            }
                                                )
                                            );
                        }

                        #endregion

                        // drwaing other players

                        #region user map drawing

                        // drawing a new user
                        else if (pkcode.Equals("Mapres"))
                        {
                            string[] spear     = { "," };
                            string[] words     = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);
                            bool     isalready = false;

                            // check a player is already exist
                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    isalready = true;
                                }
                            }

                            // if a new player, drawing start
                            if (!isalready && !words[0].Equals(Properties.Settings.Default.UserId) && Int32.Parse(words[1]) == Properties.Settings.Default.MapId)
                            {
                                Mainform.Invoke(new MethodInvoker(
                                                    delegate()
                                {
                                    Classes.OtherUser user = new Classes.OtherUser(words[0], Int32.Parse(words[1]), Int32.Parse(words[2]), Int32.Parse(words[3]), Content.Load <Texture2D>("Sprites\\" + words[4]));
                                    Users.Add(user);
                                }
                                                    )
                                                );
                            }

                            // get other player's position information - used dead reckoning
                            if (keyboardVal)
                            {
                                Send_Packet(
                                    Properties.Settings.Default.UserId + "," +
                                    Properties.Settings.Default.MapId + "," +
                                    Properties.Settings.Default.Actor_x + "," +
                                    Properties.Settings.Default.Actor_y + "," +
                                    Properties.Settings.Default.Actor_sprite + "," +
                                    Actor_activepo.X + "," +
                                    Actor_activepo.Y +
                                    ",&%*^%I+ZWQgko0LYrbcrYuZas5Q==&%*^%");
                            }
                        }

                        // remove a left user
                        else if (pkcode.Equals("MapExit"))
                        {
                            string[] spear = { "," };
                            string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                            if (Properties.Settings.Default.MapId == Int32.Parse(words[1]))
                            {
                                for (int i = 0; i < Users.Count; i++)
                                {
                                    if (Users[i].username.Equals(words[0]))
                                    {
                                        Mainform.Invoke(new MethodInvoker(
                                                            delegate()
                                        {
                                            Users[i].clear();
                                            Users.Remove(Users[i]);
                                        }
                                                            )
                                                        );
                                        break;
                                    }
                                }
                            }
                        }

                        // update other players position
                        else if (pkcode.Equals("UserMove"))
                        {
                            string[] spear   = { "," };
                            string[] words   = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);
                            bool     isexist = false;

                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        // 현재 좌표의 갱신과 움직임 설정
                                        Users[i].actor_x = Int32.Parse(words[1]);
                                        Users[i].actor_y = Int32.Parse(words[2]);
                                        Users[i].UserMove(Int32.Parse(words[4]));
                                        isexist = true;
                                    }
                                                        )
                                                    );
                                    break;
                                }
                            }

                            if (isexist == false) // if got user information failed, re-draw a new player
                            {
                                // draw a new player
                                if (!words[0].Equals(Properties.Settings.Default.UserId) && Int32.Parse(words[1]) == Properties.Settings.Default.MapId)
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        Classes.OtherUser user = new Classes.OtherUser(words[0], Int32.Parse(words[1]), Int32.Parse(words[2]), Int32.Parse(words[3]), Content.Load <Texture2D>("Sprites\\" + words[4]));
                                        Users.Add(user);
                                    }
                                                        )
                                                    );
                                }
                            }
                        }

                        // User
                        else if (pkcode.Equals("MoveStop"))
                        {
                            string[] spear = { "," };
                            string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        Users[i].UserStop();
                                    }
                                                        )
                                                    );
                                    break;
                                }
                            }
                        }

                        #endregion
                    }
                }
                catch { }

                #endregion

                // reactive chat form
                if (Properties.Settings.Default.chat_activated)
                {
                    Mainform.Invoke(new MethodInvoker(
                                        delegate()
                    {
                        Form_Chat.Activate();
                    }
                                        )
                                    );
                }

                // flush buffer and get start async receive mode
                szData2 = new byte[szData2.Length];
                e.SetBuffer(szData2, 0, szData2.Length);
                ClientSocket.ReceiveAsync(e);
            }
        }