private NetMessage WhenReqBuildCountry(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();

            const int beginningMoney = 100;


            // 로그
            Utility.Logger.GetInstance().Log(string.Format("\"{0}\"님이 건국을 요청했습니다.",
                                                           userName));


            // 유저 인증하고
            // 해당 지역이 있고
            // 유저가 아무런 땅도 가지지 않은게 맞으면
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName &&
                this.GameBoard.Board.ContainsItemAt(tileX, tileY) &&
                this.UserDirector.GetAccount(userName).AreaCount <= 0)
            {
                var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);

                // 주인없는 땅이면
                if (tile.HaveOwner == false)
                {
                    // 건국
                    this.GameBoard.SetOwnerAt(tileX, tileY, userName);
                    this.GameBoard.SetPowerAt(tileX, tileY, beginningMoney);


                    // 계정의 영토크기 정보 갱신
                    this.UserDirector.GetAccount(userName).AreaCount = 1;


                    // 건국 알림
                    NetMessageStream writer = new NetMessageStream();
                    writer.WriteData(1); // 성공여부
                    writer.WriteData(userName);
                    writer.WriteData(tileX);
                    writer.WriteData(tileY);
                    writer.WriteData(beginningMoney);

                    this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_CountryBuilt));


                    return(null);
                }
            }


            // 건국 실패 알림
            NetMessageStream failWriter = new NetMessageStream();

            failWriter.WriteData(0);

            return(failWriter.CreateMessage((int)MessageTypes.Ntf_CountryBuilt));
        }
Exemple #2
0
        private void WhenRspAllTerritory(NetMessageStream msg)
        {
            int chunkX = msg.ReadInt32();
            int chunkY = msg.ReadInt32();

            int chunkPosX = chunkX * this.GameBoard.Board.ChunkSize;
            int chunkPosY = chunkY * this.GameBoard.Board.ChunkSize;


            while (!msg.EndOfStream)
            {
                int tileX = msg.ReadInt32();
                int tileY = msg.ReadInt32();


                tileX += chunkPosX;
                tileY += chunkPosY;

                // NOTE: 없는 타일이면 자동으로 생성됨.
                var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);

                // 시야에 보이는 타일로 설정
                tile.Visible = true;

                // 동기화
                tile.Owner = this.SignDirector.LoginName;
                tile.ReadFromStreamExceptOwner(msg);
            }
        }
Exemple #3
0
        private void WhenRspUpdateChunk(NetMessageStream msg)
        {
            int chunkX = msg.ReadInt32();
            int chunkY = msg.ReadInt32();


            // 청크 생성
            this.GameBoard.Board.CreateChunkAt(chunkX, chunkY);


            // 청크 데이터 얻기
            int chunkSize = this.GameBoard.Board.ChunkSize;

            for (int x = 0; x < chunkSize; ++x)
            {
                int tileX = chunkX * chunkSize + x;


                for (int y = 0; y < chunkSize; ++y)
                {
                    int tileY = chunkY * chunkSize + y;


                    var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);

                    tile.ReadFromStream(msg);

                    tile.Visible = true;
                }
            }
        }
        private NetMessage WhenReqDestroyCompany(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();


            // 인증
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName)
            {
                user = this.UserDirector.GetAccount(user.Name);

                // 유저가 존재하고
                // 해당 타일이 존재하고
                if (user != null &&
                    this.GameBoard.Board.ContainsItemAt(tileX, tileY))
                {
                    var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);

                    // 회사 타일이면
                    if (tile != null && tile.IsCompanyTile)
                    {
                        // 폐쇄
                        this.DestroyCompany(userName, tileX, tileY);
                    }
                }
            }


            return(null);
        }
Exemple #5
0
        private void WhenNtfSetTilePower(NetMessageStream msg)
        {
            int tileX    = msg.ReadInt32();
            int tileY    = msg.ReadInt32();
            int newPower = msg.ReadInt32();


            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
            {
                // 힘 동기화
                this.GameBoard.SetPowerAt(tileX, tileY, newPower);
            }


            // 타일 Power 변경 알림
            if (m_addTilePowerCallback != null)
            {
                m_addTilePowerCallback(tileX, tileY, newPower);
                m_addTilePowerCallback = null;
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)BoardEvents.PowerUpTerritory,
                                          tileX, tileY, "");
        }
Exemple #6
0
        private void WhenRspMyAllCompanyProductList(NetMessageStream msg)
        {
            this.MyCompanyProductList.Clear();


            int count = msg.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                string company      = msg.ReadString();
                int    productCount = msg.ReadInt32();

                List <string> productList = null;

                if (this.MyCompanyProductList.ContainsKey(company))
                {
                    productList = this.MyCompanyProductList[company];
                }
                else
                {
                    productList = new List <string>();
                    this.MyCompanyProductList.Add(company, productList);
                }

                for (int t = 0; t < productCount; ++t)
                {
                    productList.Add(msg.ReadString());
                }
            }
        }
        private void WhenNtfDestroyCompany(NetMessageStream msg)
        {
            string userName    = msg.ReadString();
            int    tileX       = msg.ReadInt32();
            int    tileY       = msg.ReadInt32();
            string companyName = msg.ReadString();


            // 자신의 회사이면
            if (this.UserDataDirector.Me.Companies.Any((name) => name == companyName))
            {
                // 건물 개수 갱신
                this.UserDataDirector.AddMyCompanySiteCount(companyName, -1);
            }


            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.BoardDirector.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
            {
                // 동기화
                this.BoardDirector.GameBoard.DestroyCompany(tileX, tileY);
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)CompanyEvents.DestroyCompany,
                                          tileX, tileY, userName, new object[] { companyName });
        }
        private NetMessage WhenReqAttackTerritory(ServerVisitor client, NetMessageStream msg)
        {
            // 클릭속도 제한
            m_attackLimiter.Set(client.ID, GameValues.MinAttackDelay);
            if (m_attackLimiter.Tick(client.ID))
            {
                m_attackLimiter.Update(client.ID);


                string attackerName = msg.ReadString();
                int    tileX        = msg.ReadInt32();
                int    tileY        = msg.ReadInt32();


                // 유저 인증하고
                // 해당 지역이 있으면
                var user = this.UserDirector.GetLoginUser(client.ID);
                if (user != null && user.Name == attackerName &&
                    this.GameBoard.Board.ContainsItemAt(tileX, tileY))
                {
                    // 공격/점령
                    this.AttackTerritory(attackerName, tileX, tileY, client);
                }
            }


            return(null);
        }
Exemple #9
0
        private void WhenNtfCountryBuilt(NetMessageStream msg)
        {
            bool success = (msg.ReadInt32() != 0);

            if (success)
            {
                string userName       = msg.ReadString();
                int    tileX          = msg.ReadInt32();
                int    tileY          = msg.ReadInt32();
                int    beginningMoney = msg.ReadInt32();


                // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
                if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
                {
                    // 동기화
                    this.GameBoard.SetOwnerAt(tileX, tileY, userName);
                    this.GameBoard.SetPowerAt(tileX, tileY, beginningMoney);
                }


                // 자신의 건국인데
                if (this.SignDirector.LoginName == userName)
                {
                    // 보드에 해당 지역이 존재하지 않으면
                    if (!this.GameBoard.Board.ContainsItemAt(tileX, tileY))
                    {
                        // 해당 지역의 정보를 요청
                        this.UpdateChunkContainsTileAt(tileX, tileY);
                    }


                    // 건국 알림
                    if (m_buildCountryCallback != null)
                    {
                        m_buildCountryCallback(success, tileX, tileY);
                        m_buildCountryCallback = null;
                    }
                }


                // 이벤트 발생
                this.EventDirector.StartEvent((int)BoardEvents.BuildCountry,
                                              tileX, tileY, userName);
            }
            else
            {
                // 건국 실패 알림
                if (m_buildCountryCallback != null)
                {
                    m_buildCountryCallback(success, 0, 0);
                    m_buildCountryCallback = null;
                }
            }
        }
Exemple #10
0
        private void WhenNtfUserEnd(NetMessageStream msg)
        {
            string endUserName = msg.ReadString();
            int    tileX       = msg.ReadInt32();
            int    tileY       = msg.ReadInt32();


            // 이벤트 발생
            this.EventDirector.StartEvent((int)BoardEvents.EndUser,
                                          tileX, tileY, endUserName);
        }
Exemple #11
0
        private void WhenNtfConvertAllResource(NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();
            int    powerGet = msg.ReadInt32();


            // 이벤트 발생
            this.EventDirector.StartEvent((int)BoardEvents.ConvertAllResource,
                                          tileX, tileY, userName, new object[] { powerGet });
        }
Exemple #12
0
        private void WhenNtfDestroyChip(NetMessageStream msg)
        {
            int tileX = msg.ReadInt32();
            int tileY = msg.ReadInt32();


            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
            {
                // 동기화
                this.GameBoard.DestroyChip(tileX, tileY);
            }
        }
Exemple #13
0
        private void WhenRspNewTerritory(NetMessageStream msg)
        {
            int tileX = msg.ReadInt32();
            int tileY = msg.ReadInt32();


            // 새 영토 위치 알림
            if (m_requestNewTerritoryCallback != null)
            {
                m_requestNewTerritoryCallback(tileX, tileY);
                m_requestNewTerritoryCallback = null;
            }
        }
Exemple #14
0
        //#####################################################################################
        // 수신된 메세지 처리

        private void WhenRspCountryLocation(NetMessageStream msg)
        {
            int exist = msg.ReadInt32();
            int x     = msg.ReadInt32();
            int y     = msg.ReadInt32();


            // 국가 위치 알림
            if (m_requestCountryLocationCallback != null)
            {
                m_requestCountryLocationCallback((exist != 0), x, y);
                m_requestCountryLocationCallback = null;
            }
        }
Exemple #15
0
        //#####################################################################################
        // 수신된 메세지 처리

        private void WhenRspUserColor(NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    colorRgb = msg.ReadInt32();


            if (m_userColorMap.ContainsKey(userName))
            {
                m_userColorMap[userName] = Color.FromArgb(colorRgb);
            }
            else
            {
                m_userColorMap.Add(userName, Color.FromArgb(colorRgb));
            }


            if (m_userColorCallback != null)
            {
                m_userColorCallback(userName, Color.FromArgb(colorRgb));


                --m_userColorCallbackCount;

                if (m_userColorCallbackCount <= 0)
                {
                    m_userColorCallbackCount = 0;
                    m_userColorCallback      = null;
                }
            }
        }
        public void WhenNtfBuyProduct(NetMessageStream msg)
        {
            string companyName = msg.ReadString().Trim();
            string productName = msg.ReadString().Trim();
            int    price       = msg.ReadInt32();


            // 제품 상점 목록에서 제거
            for (int i = 0; i < this.ProductStore.Count; ++i)
            {
                var product = this.ProductStore[i];

                if (product.Seller == companyName &&
                    product.Name == productName &&
                    product.Price == product.Price)
                {
                    this.ProductStore.RemoveAt(i);
                    break;
                }
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)CompanyEvents.BuyProduct,
                                          0, 0, companyName, new object[] { productName, price });
        }
        private NetMessage WhenReqReadMail(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    index    = msg.ReadInt32();


            // 인증
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName)
            {
                user = this.UserDirector.GetAccount(user.Name);

                if (user != null)
                {
                    var mailbox = user.Mailbox;

                    if (index >= 0 && index < mailbox.Count)
                    {
                        mailbox[index].Read = true;
                    }
                }
            }


            return(null);
        }
        public void WhenNtfBuyTech(NetMessageStream msg)
        {
            string companyName = msg.ReadString().Trim();
            string techName    = msg.ReadString().Trim();
            int    price       = msg.ReadInt32();


            // 기술 상점 목록에서 제거
            for (int i = 0; i < this.TechStore.Count; ++i)
            {
                var tech = this.TechStore[i];

                if (tech.Seller == companyName &&
                    tech.Name == techName &&
                    tech.Price == tech.Price)
                {
                    this.TechStore.RemoveAt(i);
                    break;
                }
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)CompanyEvents.BuyTech,
                                          0, 0, companyName, new object[] { techName, price });
        }
        private NetMessage WhenReqDiscardProduct(ServerVisitor client, NetMessageStream msg)
        {
            string userName     = msg.ReadString();
            string companyName  = msg.ReadString().Trim();
            int    productIndex = msg.ReadInt32();


            // 인증
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName)
            {
                user = this.UserDirector.GetAccount(user.Name);
                var company = this.FindCompanyByName(companyName);

                // 유저가 존재하고
                // 존재하는 회사가 유저의 소유이고
                // 제품 번호가 유효하면
                if (user != null &&
                    company != null && company.Owner == user.Name &&
                    productIndex >= 0 && productIndex < company.ProductList.Count)
                {
                    // 회사에서 제품 폐기
                    company.RemoveProductAt(productIndex);


                    // 제품 폐기 알림
                    return(this.GetDiscardProductNotice(companyName, productIndex));
                }
            }


            return(null);
        }
Exemple #20
0
        private void WhenNtfCheckUser(NetMessageStream msg)
        {
            int data = msg.ReadInt32();


            this.WhenCheckUser(data);
        }
Exemple #21
0
        private void WhenNtfDestroyFactory(NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();


            // 공장 동기화

            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
            {
                // 동기화
                this.GameBoard.DestroyFactory(tileX, tileY);
            }
        }
        //#####################################################################################
        // 수신된 메세지 처리

        private void WhenNtfReceiveMail(NetMessageStream msg)
        {
            int    readFlag    = msg.ReadInt32();
            string fromUser    = msg.ReadString();
            string toUser      = msg.ReadString();
            string sendingDate = msg.ReadString();
            string message     = msg.ReadString();


            // 수신함에 추가
            Mail mail = new Mail()
            {
                Read        = (readFlag != 0),
                From        = fromUser,
                To          = toUser,
                SendingDate = sendingDate,
                Message     = message,
            };

            m_mailbox.Insert(0, mail);


            if (m_receiveMailCallback != null)
            {
                m_receiveMailCallback(mail);
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)CommunicationEvents.ReceiveMail,
                                          fromUser, new object[] { mail });
        }
Exemple #23
0
        private void WhenNtfSendPower(NetMessageStream msg)
        {
            int    sendingPower   = msg.ReadInt32();
            int    fromX          = msg.ReadInt32();
            int    fromY          = msg.ReadInt32();
            int    fromTilesPower = msg.ReadInt32();
            string fromTilesOwner = msg.ReadString();
            int    toX            = msg.ReadInt32();
            int    toY            = msg.ReadInt32();
            int    toTilesPower   = msg.ReadInt32();
            string toTilesOwner   = msg.ReadString();


            // 변경사항 동기화

            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.GameBoard.TileExistsAndVisibleAt(fromX, fromY))
            {
                // 동기화
                this.GameBoard.SetPowerAt(fromX, fromY, fromTilesPower);
            }

            // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
            if (this.GameBoard.TileExistsAndVisibleAt(toX, toY))
            {
                // 동기화
                this.GameBoard.SetPowerAt(toX, toY, toTilesPower);
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)BoardEvents.SendPower,
                                          fromX, fromY, fromTilesOwner, new object[] { toTilesOwner, sendingPower });
        }
Exemple #24
0
        private void WhenRspAllUserInfo(NetMessageStream msg)
        {
            bool bClear = (msg.ReadInt32() != 0);

            if (bClear)
            {
                m_userList.Clear();
            }
            else
            {
                int    colorRgb = msg.ReadInt32();
                string name     = msg.ReadString();
                int    area     = msg.ReadInt32();
                int    resource = msg.ReadInt32();
                bool   isEnd    = (msg.ReadInt32() != 0);

                // 자신의 정보이면 따로 저장
                if (name == this.SignDirector.LoginName)
                {
                    this.Me.UserColor = Color.FromArgb(colorRgb);
                    this.Me.Name      = name;
                    this.Me.AreaCount = area;
                    this.Me.Resource  = resource;
                }

                // 목록에 추가
                m_userList.Add(new GamePlayer()
                {
                    UserColor = Color.FromArgb(colorRgb),
                    Name      = name,
                    AreaCount = area,
                    Resource  = resource,
                });


                if (isEnd)
                {
                    if (m_allUserInfoCallback != null)
                    {
                        m_allUserInfoCallback();
                        m_allUserInfoCallback = null;
                    }
                }
            }
        }
        private NetMessage WhenReqConvertAllResource(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();


            // 인증
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName)
            {
                this.ConvertResource(user.Name, tileX, tileY, true);
            }


            return(null);
        }
Exemple #26
0
        private void WhenRspAllVision(NetMessageStream msg)
        {
            while (!msg.EndOfStream)
            {
                int tileX = msg.ReadInt32();
                int tileY = msg.ReadInt32();


                // 시야 타일 동기화
                var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);

                // 동기화
                tile.ReadFromStream(msg);

                // 시야에 보이는 타일로 설정
                tile.Visible = true;
            }
        }
        private NetMessage WhenReqEditTileSign(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();
            int    tileX    = msg.ReadInt32();
            int    tileY    = msg.ReadInt32();
            string sign     = msg.ReadString();


            // 인증
            var user = this.UserDirector.GetLoginUser(client.ID);

            if (user != null && user.Name == userName)
            {
                this.EditSign(userName, tileX, tileY, sign);
            }


            return(null);
        }
Exemple #28
0
        private void WhenRspSetScreen(NetMessageStream msg)
        {
            while (!msg.EndOfStream)
            {
                int tileX = msg.ReadInt32();
                int tileY = msg.ReadInt32();

                var serverTile = new Tile();
                serverTile.ReadFromStream(msg);

                // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
                if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
                {
                    // 동기화
                    var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);
                    tile.FromTile(serverTile);
                }
            }
        }
Exemple #29
0
        private void WhenRspVision(NetMessageStream msg)
        {
            int centerX      = msg.ReadInt32();
            int centerY      = msg.ReadInt32();
            int visionLength = msg.ReadInt32();

            int           userTableCount = msg.ReadInt32();
            List <string> userNameTable  = new List <string>();

            for (int i = 0; i < userTableCount; ++i)
            {
                userNameTable.Add(msg.ReadString());
            }


            int beginX = centerX - visionLength;
            int beginY = centerY - visionLength;
            int endX   = beginX + visionLength * 2;
            int endY   = beginY + visionLength * 2;


            for (int x = beginX; x <= endX; ++x)
            {
                for (int y = beginY; y <= endY; ++y)
                {
                    var tile = this.GameBoard.Board.GetItemAt(x, y);


                    // 시야에 보이는 타일로 설정
                    tile.Visible = true;

                    // 주인 동기화
                    int userNameIndex = msg.ReadInt32();
                    if (userNameIndex < userNameTable.Count)
                    {
                        tile.Owner = userNameTable[userNameIndex];
                    }

                    // 나머지 정보 동기화
                    tile.ReadFromStreamExceptOwner(msg);
                }
            }
        }
Exemple #30
0
        private void WhenNtfAttackTerritory(NetMessageStream msg)
        {
            string attackerName = msg.ReadString();
            int    targetX      = msg.ReadInt32();
            int    targetY      = msg.ReadInt32();

            string victimName = msg.ReadString();

            int changedCount = msg.ReadInt32();

            for (int i = 0; i < changedCount; ++i)
            {
                int tileX = msg.ReadInt32();
                int tileY = msg.ReadInt32();


                // NOTE: 무조건 읽도록 함.
                Tile tempTile = new Tile();
                tempTile.ReadFromStream(msg);


                // 클라측 보드에 존재하는 지역이고 시야 내의 타일이면
                if (this.GameBoard.TileExistsAndVisibleAt(tileX, tileY))
                {
                    // 동기화
                    var tile = this.GameBoard.Board.GetItemAt(tileX, tileY);
                    tile.FromTile(tempTile);
                }
            }


            if (m_attackCallback != null)
            {
                m_attackCallback(attackerName, targetX, targetY);
                m_attackCallback = null;
            }


            // 이벤트 발생
            this.EventDirector.StartEvent((int)BoardEvents.AttackTerritory,
                                          targetX, targetY, attackerName, new object[] { victimName });
        }