Exemple #1
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 });
        }
        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 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 #4
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());
                }
            }
        }
        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 });
        }
        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 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 });
        }
        private NetMessage WhenReqProduceProduct(ServerVisitor client, NetMessageStream msg)
        {
            string userName    = msg.ReadString();
            string companyName = msg.ReadString().Trim();
            string techName    = msg.ReadString().Trim();


            // 인증
            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 &&
                    techName.Length > 0)
                {
                    Chip techChip = company.GetTech(techName);

                    if (techChip != null)
                    {
                        int produceFee      = techChip.Program.Count * GameValues.ProduceFeePerProgramLine;
                        int maxProductCount = this.GetCompanySiteCount(companyName) * GameValues.CompanyProductSizePerSite;


                        // 생산비가 충분하고
                        // 여유공간이 있으면
                        if (user.Resource >= produceFee &&
                            company.ProductList.Count < maxProductCount)
                        {
                            // 생산비 차감
                            user.Resource -= produceFee;


                            // 회사 창고에 생산품 추가
                            company.AddProduct(techChip.Clone());


                            // 생산 알림
                            NetMessageStream writer = new NetMessageStream();
                            writer.WriteData(companyName);
                            writer.WriteData(techName);

                            return(writer.CreateMessage((int)MessageTypes.Rsp_ProduceProduct));
                        }
                    }
                }
            }


            return(null);
        }
Exemple #9
0
        public void ReadFromStream(NetMessageStream stream)
        {
            this.Parameters.Clear();


            this.Name = stream.ReadString();

            int paramCount = stream.ReadInt32();

            for (int i = 0; i < paramCount; ++i)
            {
                this.Parameters.Add(stream.ReadString());
            }
        }
Exemple #10
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;
                }
            }
        }
        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);
        }
        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 #13
0
        private NetMessage WhenReqMyAllCompanyName(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();


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

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

                if (user != null)
                {
                    // 회사 이름 전송
                    NetMessageStream writer = new NetMessageStream();
                    writer.WriteData(user.Companies.Count);

                    foreach (string companyName in user.Companies)
                    {
                        writer.WriteData(companyName);
                    }


                    return(writer.CreateMessage((int)MessageTypes.Rsp_MyAllCompanyName));
                }
            }


            return(null);
        }
        private NetMessage WhenReqMailbox(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();


            // 인증
            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;

                    for (int i = mailbox.Count - 1; i >= 0; --i)
                    {
                        this.NtfReceiveMailTo(client, mailbox[i]);
                    }
                }
            }


            return(null);
        }
        private NetMessage WhenReqAllSellingTech(ServerVisitor client, NetMessageStream msg)
        {
            string userName = msg.ReadString();


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

            if (user != null && user.Name == userName)
            {
                foreach (var item in m_techStore)
                {
                    // 해당 기술 구매가 허가된 유저라면
                    if (item.TargetUser.Length <= 0 ||
                        item.TargetUser == user.Name)
                    {
                        // 정보 전송
                        NetMessageStream writer = new NetMessageStream();
                        writer.WriteData(item.Seller);
                        writer.WriteData(item.Name);
                        writer.WriteData(item.Price);

                        client.Sender.SendMessage(writer.CreateMessage((int)MessageTypes.Ntf_SellTech));
                    }
                }
            }


            return(null);
        }
        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);
        }
        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);
        }
        private NetMessage WhenReqTechProgram(ServerVisitor client, NetMessageStream msg)
        {
            string userName    = msg.ReadString();
            string companyName = msg.ReadString().Trim();
            string techName    = msg.ReadString().Trim();


            // 인증
            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 &&
                    techName.Length > 0)
                {
                    Chip techChip = company.GetTech(techName);

                    // 해당 기술이 회사에 존재하면
                    if (techChip != null)
                    {
                        var program = techChip.Program;

                        // 기술 프로그램 전송
                        NetMessageStream writer = new NetMessageStream();
                        writer.WriteData(companyName);
                        writer.WriteData(techName);
                        writer.WriteData(program.Count);
                        foreach (var cmd in program)
                        {
                            cmd.WriteToStream(writer);
                        }

                        return(writer.CreateMessage((int)MessageTypes.Rsp_TechProgram));
                    }
                }
            }


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


            // 제품 상점 목록에 추가
            SellingTech newProduct = new SellingTech()
            {
                Seller = companyName,
                Name   = productName,
                Price  = price,
            };

            this.ProductStore.Add(newProduct);
        }
        public void WhenNtfSellTech(NetMessageStream msg)
        {
            string companyName = msg.ReadString().Trim();
            string techName    = msg.ReadString().Trim();
            int    price       = msg.ReadInt32();


            // 기술 상점 목록에 추가
            SellingTech newTech = new SellingTech()
            {
                Seller = companyName,
                Name   = techName,
                Price  = price,
            };

            this.TechStore.Add(newTech);
        }
        //#####################################################################################
        // 수신된 메세지 처리

        private NetMessage WhenReqSendMail(ServerVisitor client, NetMessageStream msg)
        {
            string userName   = msg.ReadString();
            string targetName = msg.ReadString();
            string date       = msg.ReadString();
            string message    = msg.ReadString();


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

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

                if (targetUser != null)
                {
                    Mail mail = new Mail()
                    {
                        Read        = false,
                        From        = userName,
                        To          = targetName,
                        SendingDate = date,
                        Message     = message,
                    };

                    // 메일함에 추가
                    targetUser.Mailbox.Insert(0, mail);

                    // 메일함의 크기가 너무 크면 오래된 메일부터 지움.
                    if (targetUser.Mailbox.Count > this.MaxMailboxSize)
                    {
                        targetUser.Mailbox.RemoveRange(this.MaxMailboxSize, targetUser.Mailbox.Count - this.MaxMailboxSize);
                    }


                    // 메일 수신 알림
                    this.NtfReceiveMailTo(targetName, mail);
                }
            }


            return(null);
        }
        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 #23
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 #24
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 });
        }
Exemple #25
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);
        }
        //#####################################################################################
        // 수신된 메세지 처리

        private void WhenRspRegisterCompany(NetMessageStream msg)
        {
            RegisterCompanyResults result = (RegisterCompanyResults)msg.ReadInt32();
            string name = msg.ReadString();


            if (m_registerCompanyCallback != null)
            {
                m_registerCompanyCallback(result);
                m_registerCompanyCallback = null;
            }
        }
        public void WhenRspProduceProduct(NetMessageStream msg)
        {
            string companyName = msg.ReadString();
            string productName = msg.ReadString();


            // 동기화
            this.UserDataDirector.AddProductInMyCompany(companyName, productName);


            if (m_produceProductCallback != null)
            {
                m_produceProductCallback();
                m_produceProductCallback = null;
            }

            if (this.WhenCompanyProductListChanged != null)
            {
                WhenCompanyProductListChanged();
            }
        }
        public void WhenRspDiscardTech(NetMessageStream msg)
        {
            string companyName = msg.ReadString();
            string techName    = msg.ReadString();


            // 동기화
            this.UserDataDirector.RemoveTechInMyCompany(companyName, techName);


            if (m_discardTechCallback != null)
            {
                m_discardTechCallback();
                m_discardTechCallback = null;
            }

            if (WhenCompanyTechListChanged != null)
            {
                WhenCompanyTechListChanged();
            }
        }
Exemple #29
0
        //#####################################################################################
        // 수신된 메세지 처리

        private void WhenNtfNotice(NetMessageStream msg)
        {
            // 공지 갱신
            this.LatestNotice = msg.ReadString();

            // 공지 갱신 알림
            if (m_noticeCallback != null)
            {
                m_noticeCallback(this.LatestNotice);
                m_noticeCallback = null;
            }
        }
Exemple #30
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 });
        }