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); }
public void DevelopTech(string companyName, string techName, List <Command> program, Action <DevelopTechResults> callbackAsync) { m_developTechCallback = callbackAsync; companyName = companyName.Trim(); techName = techName.Trim(); // 자신의 회사이고 // 기술 이름이 유효하고 // 프로그램이 존재하면 if (this.UserDataDirector.CheckMyCompany(companyName) && techName.Length > 0 && program != null) { // 기술 등록 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(companyName); writer.WriteData(techName); writer.WriteData(program.Count); foreach (var cmd in program) { cmd.WriteToStream(writer); } this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_DevelopTech)); } }
private NetMessage WhenReqBuildCountry(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); int tileX = msg.ReadData <int>(); int tileY = msg.ReadData <int>(); 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 <int>(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 <int>(0); return(failWriter.CreateMessage((int)MessageTypes.Ntf_CountryBuilt)); }
private NetMessage WhenReqAllSellingTech(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); // 인증 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); }
public void EditSign(string userName, int tileX, int tileY, string sign) { // 금지문자 대체 sign = sign.Replace('\\', '/'); // 해당 타일이 존재하고 // 요청자의 타일이고 // 설정할 푯말이 제한 길이를 넘지 않으면 if (this.GameBoard.Board.ContainsItemAt(tileX, tileY) && this.GameBoard.GetOwnerAt(tileX, tileY) == userName && sign.Length <= GameValues.MaxSignLength) { // 푯말을 설정하고 this.GameBoard.SetSignAt(tileX, tileY, sign); // 변경사항을 모두에게 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(userName); writer.WriteData(tileX); writer.WriteData(tileY); writer.WriteData(sign); this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_EditTileSign)); } }
public void DestroyCompany(string userName, int tileX, int tileY) { // 건물 개수 갱신 string companyName = this.GetCompanyNameAt(tileX, tileY); if (companyName.Length > 0) { this.AddCompanySiteCount(companyName, -1); } // 회사 폐쇄 this.GameBoard.DestroyCompany(tileX, tileY); this.SetCompanyNameAt(tileX, tileY, ""); // 폐쇄 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(userName); writer.WriteData(tileX); writer.WriteData(tileY); writer.WriteData(companyName); this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_DestroyCompany)); }
public NetMessage GetDiscardProductNotice(string companyName, int productIndex) { NetMessageStream writer = new NetMessageStream(); writer.WriteData(companyName); writer.WriteData(productIndex); return(writer.CreateMessage((int)MessageTypes.Rsp_DiscardProduct)); }
private NetMessage WhenReqProduceProduct(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string companyName = msg.ReadData <string>().Trim(); string techName = msg.ReadData <string>().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); }
public NetMessage GetNoticeDevelopTech(string buyerName, string techName, DevelopTechResults result) { NetMessageStream addTechMsg = new NetMessageStream(); addTechMsg.WriteData(buyerName); addTechMsg.WriteData(techName); addTechMsg.WriteData((int)result); return(addTechMsg.CreateMessage((int)MessageTypes.Rsp_DevelopTech)); }
public void ReadMail(int index) { // 메일 읽음처리 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(index); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_ReadMail)); }
protected void NoticeDestroyChip(int tileX, int tileY) { NetMessageStream writer = new NetMessageStream(); writer.WriteData(tileX); writer.WriteData(tileY); this.NoticeToUsersInVision(writer.CreateMessage((int)MessageTypes.Ntf_DestroyChip), tileX, tileY); }
public void WriteToStream(NetMessageStream stream) { stream.WriteData(this.Name); stream.WriteData(this.Parameters.Count); for (int i = 0; i < this.Parameters.Count; ++i) { stream.WriteData(this.Parameters[i]); } }
public void UpdateChunkContainsTileAt(int tileX, int tileY) { // 해당 위치의 타일을 포함하는 청크 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(tileX); writer.WriteData(tileY); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_Chunk)); }
public void SendPower(string userName, int fromX, int fromY, int toX, int toY) { Point fromTilePos = new Point(fromX, fromY); Point toTilePos = new Point(toX, toY); // 유효한 힘 보내기라면 if (this.GameBoard.CheckCanSendPower(userName, fromTilePos, toTilePos)) { // 힘 전달 int sendingPower = this.GameBoard.SendPower(fromTilePos, toTilePos); var fromTile = this.GameBoard.Board.GetItemAt(fromX, fromY); var toTile = this.GameBoard.Board.GetItemAt(toX, toY); // 변경사항 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(sendingPower); writer.WriteData(fromX); writer.WriteData(fromY); writer.WriteData(fromTile.Power); writer.WriteData(fromTile.Owner); writer.WriteData(toX); writer.WriteData(toY); writer.WriteData(toTile.Power); writer.WriteData(toTile.Owner); this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_SendPower)); } }
protected void NtfSetPower(int tileX, int tileY, int newPower) { NetMessageStream writer = new NetMessageStream(); writer.WriteData(tileX); writer.WriteData(tileY); writer.WriteData(newPower); this.NoticeToUsersInVision(writer.CreateMessage((int)MessageTypes.Ntf_SetTilePower), tileX, tileY); }
//##################################################################################### protected void NtfReceiveMailTo(ServerVisitor targetClient, Mail mail) { NetMessageStream writer = new NetMessageStream(); writer.WriteData <int>(mail.Read ? 1 : 0); writer.WriteData(mail.From); writer.WriteData(mail.To); writer.WriteData(mail.SendingDate); writer.WriteData(mail.Message); targetClient.Sender.SendMessage(writer.CreateMessage((int)MessageTypes.Ntf_ReceiveMail)); }
public void UpdateMyScreen(int beginX, int beginY, int width, int height) { NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(beginX); writer.WriteData(beginY); writer.WriteData(width); writer.WriteData(height); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_SetScreen)); }
//##################################################################################### // 사용자 입력 처리 public void RegisterCompany(string name, Action <RegisterCompanyResults> callbackAsync) { m_registerCompanyCallback = callbackAsync; // 회사 등록 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(name.Trim()); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_RegisterCompany)); }
public void AddTilePower(int tileX, int tileY, Action <int, int, int> callbackAsync) { m_addTilePowerCallback = callbackAsync; // Power 변경 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(tileX); writer.WriteData(tileY); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_AddTilePower)); }
public void Register(string name, string password, Color userColor, Action <RegisterResults> callbackAsync) { m_registerCallback = callbackAsync; // 계정생성 요청 전송 NetMessageStream writer = new NetMessageStream(); writer.WriteData(name); writer.WriteData(password); writer.WriteData(userColor.ToArgb()); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_Register)); }
public void AttackTerritory(int tileX, int tileY, Action <string, int, int> callbackAsync) { m_attackCallback = callbackAsync; // 현재 플레이어에게 보이는 영토만 선택가능 if (this.GameBoard.Board.ContainsItemAt(tileX, tileY)) { // 공격 가능한지 확인 bool bCanAttack = false; int[] nearX = new int[] { tileX, tileX + 1, tileX, tileX - 1 }; int[] nearY = new int[] { tileY - 1, tileY, tileY + 1, tileY }; for (int i = 0; i < 4; ++i) { if (this.GameBoard.Board.ContainsItemAt(nearX[i], nearY[i])) { var nearTile = this.GameBoard.Board.GetItemAt(nearX[i], nearY[i]); if (nearTile != null && nearTile.Owner == this.SignDirector.LoginName) { bCanAttack = true; break; } } } if (bCanAttack) { // 공격/점령 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(tileX); writer.WriteData(tileY); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_AttackTerritory)); } } }
//##################################################################################### // 사용자 입력 처리 public void Login(string name, string password, Action <LoginResults> callbackAsync) { m_loginCallback = callbackAsync; m_tryName = name; // 로그인 요청 메세지 전송 NetMessageStream writer = new NetMessageStream(); writer.WriteData(name); writer.WriteData(password); writer.WriteData(Application.ProductVersion.ToString()); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_Login)); }
private NetMessage WhenReqAllUserInfo(ServerVisitor client, NetMessageStream msg) { var accounts = this.UserDirector.Accounts; if (accounts.Length > 0) { NetMessageStream writer = null; writer = new NetMessageStream(); writer.WriteData(1); client.Sender.SendMessage(writer.CreateMessage((int)MessageTypes.Rsp_AllUserInfo)); foreach (var account in accounts) { writer = new NetMessageStream(); writer.WriteData(0); writer.WriteData(account.UserColor.ToArgb()); writer.WriteData(account.Name); writer.WriteData(account.AreaCount); writer.WriteData(account.Resource); writer.WriteData((account == accounts.Last()) ? 1 : 0); client.Sender.SendMessage(writer.CreateMessage((int)MessageTypes.Rsp_AllUserInfo)); } } return(null); }
private NetMessage WhenReqTechProgram(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string companyName = msg.ReadData <string>().Trim(); string techName = msg.ReadData <string>().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); }
private NetMessage WhenReqMyAllCompanySiteCount(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 wholeCompanySiteCount = this.CompanyDirector.CompanySiteCount; Dictionary <string, int> myCompanySiteCount = new Dictionary <string, int>(); var myCompanies = user.Companies; foreach (string myCompany in myCompanies) { if (wholeCompanySiteCount.ContainsKey(myCompany)) { myCompanySiteCount.Add(myCompany, wholeCompanySiteCount[myCompany]); } } // 회사별 건물 개수 전송 NetMessageStream writer = new NetMessageStream(); writer.WriteData(myCompanySiteCount.Count); foreach (var company_count in myCompanySiteCount) { writer.WriteData(company_count.Key); writer.WriteData(company_count.Value); } return(writer.CreateMessage((int)MessageTypes.Rsp_MyAllCompanySiteCount)); } } return(null); }
//##################################################################################### // 수신된 메세지 처리 private NetMessage WhenReqNotice(ServerVisitor client, NetMessageStream msg) { NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.Notice); return(writer.CreateMessage((int)MessageTypes.Ntf_Notice)); }
//##################################################################################### public void CheckUser() { NetMessageStream writer = new NetMessageStream(); writer.WriteData(Utility.Random.Next(9)); this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_CheckUser)); }
public void SendTerritoryPower(int fromX, int fromY, int toX, int toY) { // 힘을 보낼 수 있으면 if (this.GameBoard.CheckCanSendPower(this.SignDirector.LoginName, new System.Drawing.Point(fromX, fromY), new System.Drawing.Point(toX, toY))) { // 힘 전달 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); writer.WriteData(fromX); writer.WriteData(fromY); writer.WriteData(toX); writer.WriteData(toY); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_SendPower)); } }
public void RequestAllSellingProduct() { // 제품 상점 정보 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_AllSellingProduct)); }
public void RequestMyAllCompanyProductList() { // 자신의 모든 회사별 제품 정보 요청 NetMessageStream writer = new NetMessageStream(); writer.WriteData(this.SignDirector.LoginName); this.Client.SendMessage(writer.CreateMessage((int)MessageTypes.Req_MyAllCompanyProductList)); }