/// <summary> /// 循环接收消息 /// </summary> private void RecvMsgLoop() { while (true) { try { //接收到的一条消息 ProtoMessage message = RecvOneMessage(stream); if (message == null) { recvMsgQueue.Enqueue(new ProtoMessage(SERVER_DISCONNECTED, null)); Console.WriteLine("RecvThread finished."); return; } recvMsgQueue.Enqueue(message); } catch (System.Exception ex) { Console.WriteLine("RecvThread error!!!"); Console.WriteLine(ex.ToString()); Console.WriteLine(ex.StackTrace); recvMsgQueue.Enqueue(new ProtoMessage(CLIENT_ERROR, null)); Console.WriteLine("RecvThread finished."); return; } } }
public bool Filter(ProtoMessage msg) { switch (msg.Type) { case CmdType.PU.TOAST: case CmdType.HU.TOAST: case CmdType.GU.TOAST_V6: case CmdType.CU.TOAST_V6: ProcessToast(msg); break; case CmdType.CU.B_SYS_TEXT_MSG_V6: ProcessSysTextMsg(msg); break; case CmdType.PU.CLIENT_VERSION_RESULT: ProcessClientVersionResult(msg); break; case CmdType.HU.MAIL_BRIEF_LIST_RESULT: ProcessMailBriefList(msg); break; case CmdType.HU.MAIL_CONTENT_RESULT: ProcessMailContent(msg); break; } // 并不会过滤掉任何消息。 return(false); }
public void Send(ProtoMessage message, bool encrypt = true) { NetOutgoingMessage msg = client.CreateMessage(); MemoryStream ms = new MemoryStream(); try { Serializer.SerializeWithLengthPrefix <ProtoMessage>(ms, message, ProtoBuf.PrefixStyle.Fixed32); msg.Write(ms.GetBuffer()); if (encryptionAlg != null && encrypt) { msg.Encrypt(encryptionAlg); } var result = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); client.FlushSendQueue(); } catch (Exception e) { Debug.Log("Connected - remote hail message\n" + e.GetType() + "\n" + e.Message + "\n" + e.StackTrace); Exception inner; if (e.InnerException != null) { inner = e.InnerException; Debug.Log("Inner Exception:\n" + inner.GetType() + "\n" + inner.Message + "\n" + inner.StackTrace); } } }
/// <summary> /// Request that a season update be performed. Note that this is an admin command /// </summary> public void SeasonUpdate() { ProtoMessage updateRequest = new ProtoMessage(); updateRequest.ActionType = Actions.SeasonUpdate; net.Send(updateRequest); }
private void ProcessMailBriefList(ProtoMessage msg) { if (msg == null) { return; } var res = msg.Content as MailBriefListResult; if (res == null) { return; } var list = res.mail_brief; if (list.Count <= 0) { return; } foreach (var m in list) { if (m == null) { continue; } m.title = ReplaceContent(m.title); m.content = ReplaceContent(m.content); } }
public ProtoMessage AttackArmy(string aID, TextTestClient client) { ProtoPlayerCharacter protoMessage = new ProtoPlayerCharacter(); protoMessage.Message = client.charID; protoMessage.ActionType = Actions.ViewChar; client.net.Send(protoMessage); var locReply = GetActionReply(Actions.ViewChar, client); var locResult = (ProtoPlayerCharacter)locReply.Result; ProtoMessage protoAttack = new ProtoMessage(); protoAttack.ActionType = Actions.Attack; protoAttack.Message = locResult.armyID; protoAttack.MessageFields = new string[] { aID }; client.net.Send(protoAttack); var reply = GetActionReply(Actions.Attack, client); if (reply.GetType() == typeof(ProtoBattle)) { return(reply.Result as ProtoBattle); } else { return(reply.Result); } }
public void SpyCharacterTooFar() { ProtoMessage ignore = null; // (need to move the character to the same location as the playercharacter) this.SpyCharacterTest(client, MyPlayerCharacter.charID, NotMyFamily.charID, true); }
private void BtnRemoveBailiff() { //string bailiff = currentlyViewedFief.bailiff.charID; string fiefName = currentlyViewedFief.FiefName; ProtoMessage reply = RemoveBailiff(currentlyViewedFief.fiefID, tclient); DisplayMessages responseType = reply.ResponseType; if (responseType == DisplayMessages.Success) { DisplayMessageToUser(currentlyViewedFief.bailiff.charID + " removed from bailiff position in " + fiefName + "."); } else if (responseType == DisplayMessages.FiefNoBailiff) { DisplayMessageToUser("There is no bailiff to remove in " + fiefName + "."); } else if (responseType == DisplayMessages.ErrorGenericUnauthorised) { DisplayMessageToUser("You are not authorised to make changes to " + fiefName + "."); } else { DisplayMessageToUser("ERROR: Response type: " + responseType.ToString()); } DisplayFiefDetails(); }
public void Enqueue(ProtoMessage msg) { lock (this) { q.Enqueue(msg); } }
public void DisplayHire(ProtoMessage recruitProtoBuf) { if (recruitProtoBuf.ResponseType == DisplayMessages.CharacterRecruitOwn) { Console.WriteLine("Recruit from a fief you own!"); } else if (recruitProtoBuf.ResponseType == DisplayMessages.CharacterRecruitAlready) { Console.WriteLine("You have already recruited!"); } else if (recruitProtoBuf.ResponseType == DisplayMessages.CharacterRecruitInsufficientFunds) { Console.WriteLine("Insufficient recruitment funds!"); } else { var recruitProtoBufCast = (ProtoRecruit)recruitProtoBuf; Console.WriteLine("-----------------------------"); Console.WriteLine("Recruit Report"); Console.WriteLine("-----------------------------"); Console.WriteLine("Army ID: " + recruitProtoBufCast.armyID); Console.WriteLine("Recruitment Cost: " + recruitProtoBufCast.cost); Console.WriteLine("Amount of Recruits: " + recruitProtoBufCast.amount); Console.WriteLine("-----------------------------"); } }
// Start is called before the first frame update new void Start() { btnAttackArmy.onClick.AddListener(BtnAttackArmy); lblMessageForUser.text = ""; btnAttackArmy.interactable = false; ProtoMessage reply = GetArmyDetails(armyToViewID, tclient); if (reply.ResponseType == DisplayMessages.Success) { currentlyViewedArmy = (ProtoArmy)reply; DisplayArmyDetails(); // Can't attack if you don't have an army. if (!string.IsNullOrWhiteSpace(protoClient.activeChar.armyID)) { // Can't attack your own armies. if (!currentlyViewedArmy.ownerID.Equals(protoClient.playerChar.charID)) { if (currentlyViewedArmy.location.Equals(protoClient.playerChar.location)) { btnAttackArmy.interactable = true; } } } } else { DisplayMessageToUser("ERROR: Response type: " + reply.ResponseType.ToString()); } }
public void DisplayChangePilllage(ProtoMessage message) { Console.WriteLine("-----------------------------"); Console.Write("Change of auto pillage to maintain army: "); Console.WriteLine(message.ResponseType); Console.WriteLine("-----------------------------"); }
public void DisplayChangeDef(ProtoMessage message) { Console.WriteLine("-----------------------------"); Console.Write("Change of auto support when ally defends: "); Console.WriteLine(message.ResponseType); Console.WriteLine("-----------------------------"); }
protected void SendOneMessage(Stream s, ProtoMessage msg) { //构造要发出的消息数据 MemoryStream ms = msg.Data; int dataLength = (int)ms.Length; byte[] buf = new byte[4 + dataLength]; //设置头部 buf[0] = (byte)((msg.Type >> 8) & 0xFF); buf[1] = (byte)(msg.Type & 0xFF); buf[2] = (byte)((dataLength >> 8) & 0xFF); buf[3] = (byte)(dataLength & 0xFF); ms.Position = 0; int remainLen = dataLength; while (remainLen > 0) { remainLen -= ms.Read(buf, 4 + dataLength - remainLen, remainLen); } s.Write(buf, 0, 4 + dataLength); }
/// <summary> /// Processes functions involved in lodging a new ownership (and kingship) challenge /// Returns ProtoMessage in case of error /// </summary> public ProtoMessage LodgeOwnershipChallenge(PlayerCharacter challenger) { bool proceed = true; ProtoMessage result = null; // ensure aren't current owner if (challenger == this.owner) { result = new ProtoMessage(); result.ResponseType = DisplayMessages.KingdomAlreadyKing; } else { // create and send new OwnershipChallenge OwnershipChallenge newChallenge = new OwnershipChallenge(Globals_Game.GetNextOwnChallengeID(), challenger.charID, "kingdom", this.id); proceed = Globals_Game.AddOwnershipChallenge(newChallenge, out result); } if (proceed) { // create and send journal entry // get interested parties PlayerCharacter currentOwner = this.owner; // ID uint entryID = Globals_Game.GetNextJournalEntryID(); // date uint year = Globals_Game.clock.currentYear; byte season = Globals_Game.clock.currentSeason; // location string entryLoc = this.id; // journal entry personae string allEntry = "all|all"; string currentOwnerEntry = currentOwner.charID + "|king"; string challengerEntry = challenger.charID + "|pretender"; string[] entryPersonae = new string[] { currentOwnerEntry, challengerEntry, allEntry }; // entry type string entryType = "depose_new"; // journal entry description string[] fields = new string[4]; fields[0] = this.name; fields[1] = this.id; fields[2] = challenger.firstName + " " + challenger.familyName; fields[3] = currentOwner.firstName + " " + currentOwner.familyName; ProtoMessage ownershipChallenge = new ProtoMessage(); ownershipChallenge.MessageFields = fields; ownershipChallenge.ResponseType = DisplayMessages.KingdomOwnershipChallenge; // create and send a proposal (journal entry) JournalEntry myEntry = new JournalEntry(entryID, year, season, entryPersonae, entryType, ownershipChallenge, loc: entryLoc); Globals_Game.AddPastEvent(myEntry); } return(result); }
static string ProtoMessageToString(ProtoMessage msg) { if (!msg.HasPayload) { return("ERROR in ProtoMessage: Corrupted execution event, no payload found"); } var _str = "ProtoMessage{"; switch ((ProtoPayloadType)msg.PayloadType) { case ProtoPayloadType.PROTO_MESSAGE: var _msg = ProtoMessage.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += ProtoMessageToString(_msg); break; case ProtoPayloadType.HEARTBEAT_EVENT: var _hb = ProtoHeartbeatEvent.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += "Heartbeat"; break; case ProtoPayloadType.ERROR_RES: var _err = ProtoErrorRes.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += "ErrorResponse{errorCode:" + _err.ErrorCode + (_err.HasDescription ? ", description:" + _err.Description : "") + "}"; break; default: _str += OpenApiMessageToString(msg); break; } _str += (msg.HasClientMsgId ? ", clientMsgId:" + msg.ClientMsgId : "") + "}"; return(_str); }
public async Task SendMessage(ProtoMessage message) { CheckIsDisposed(); try { var messageByte = message.ToByteArray(); var length = BitConverter.GetBytes(messageByte.Length).Reverse().ToArray(); LastSentMessageTime = DateTime.Now; await Write(messageByte, length); } catch (OperationCanceledException) { } catch (Exception ex) { if (!Streams.SenderExceptionStream.Observers.Any()) { throw; } Streams.OnSenderException(ex); } }
/* * public static ProtoMessage TryForChild(string charID, TextTestClient client) * { * ProtoMessage protoMessage = new ProtoMessage(); * protoMessage.ActionType = Actions.TryForChild; * protoMessage.Message = charID; * client.net.Send(protoMessage); * var reply = GetActionReply(Actions.TryForChild, client); * return reply; * } */ /// <summary> /// siege functions /// </summary> /// <param name="client"></param> /// <returns></returns> public static ProtoMessage SiegeCurrentFief(TextTestClient client) { ProtoPlayerCharacter protoMessage = new ProtoPlayerCharacter(); protoMessage.Message = "Char_158"; protoMessage.ActionType = Actions.ViewChar; client.net.Send(protoMessage); var locReply = GetActionReply(Actions.ViewChar, client); var locResult = (ProtoPlayerCharacter)locReply; ProtoMessage protoSiegeStart = new ProtoMessage(); protoSiegeStart.ActionType = Actions.BesiegeFief; protoSiegeStart.Message = locResult.armyID; client.net.Send(protoSiegeStart); var reply = GetActionReply(Actions.BesiegeFief, client); if (reply.GetType() == typeof(ProtoSiegeDisplay)) { return(reply as ProtoSiegeDisplay); } else { return(reply); } }
/// <summary> /// Get list of sieges you are currently involved in, whether as a besieger or defender /// </summary> public void GetSiegeList() { ProtoMessage siegelist = new ProtoMessage(); siegelist.ActionType = Actions.SiegeList; net.Send(siegelist); }
private void OnNext(ProtoMessage protoMessage) { foreach (var(_, observer) in _observers) { try { var message = MessageFactory.GetMessage(protoMessage); if (protoMessage.HasClientMsgId || message == null) { observer.OnNext(protoMessage); } if (message != null) { observer.OnNext(message); } } catch (Exception ex) { var observerException = new ObserverException(ex, observer); OnError(observerException); } } }
private void chatPrivateMessagePushMessageEventHandler(ProtoMessage message) { Debug.WriteLine("ChatPrivateMessagePushMessageEvent handler"); ChatPrivateMessagePushMessage incomeMessage = message.ChatPrivateMessagePushMessage; string senderEMail = incomeMessage.SenderEmail; ChatMessage chatmess = incomeMessage.Message; foreach (ContactList group in Root) { foreach (Contact contact in group.Contacts) { if (senderEMail == contact.EMail) { //Debug.Write() Message m = new Message() { SenderEMail = senderEMail, RecevieEMail = model.CurrentUser.EMail, Content = chatmess.MsgContents, Data_time = chatmess.DateTime, SenderNickname = contact.Nickname }; contact.ChatMessageList.Add(m); break; } } } if (currentSystemState == SystemState.Chatting) { eventAggregator.GetEvent <MouseKeyDownAContactEvent>().Publish(CurrentContact.EMail); } }
private void userInfoQueryResponseEventHandler(ProtoMessage message) { Debug.WriteLine("UserInfoQueryResponseEvent handler"); var _user = message.UserInfoQueryResponse; CurrentUser.EMail = _user.MailAddress; CurrentUser.Nickname = _user.Nickname; CurrentUser.Sex = _user.Sex; CurrentUser.Age = _user.Age; CurrentUser.Country = _user.Country; CurrentUser.Province = _user.Province; CurrentUser.City = _user.City; CurrentUser.CreateDate = _user.CreateDate; model.CurrentUser.EMail = _user.MailAddress; model.CurrentUser.Nickname = _user.Nickname; model.CurrentUser.Sex = _user.Sex; model.CurrentUser.Age = _user.Age; model.CurrentUser.Country = _user.Country; model.CurrentUser.Province = _user.Province; model.CurrentUser.City = _user.City; model.CurrentUser.CreateDate = _user.CreateDate; Debug.WriteLine("CURRENT USERINFO"); Debug.Write(CurrentUser.Age.ToString()); Debug.Write(CurrentUser.City); Debug.Write(CurrentUser.Country); Debug.Write(CurrentUser.CreateDate); Debug.Write(CurrentUser.EMail); Debug.Write(CurrentUser.Nickname); Debug.WriteLine(CurrentUser.Province); //model.sendContactApplyRequest(currentUser.EMail, SearchBox_UserEMail, AddContactDiscription); }
public static string GetTextPresentation(this ProtoMessage msg) { if (!msg.HasPayload) { return("ERROR in ProtoMessage: Corrupted execution event, no payload found"); } var _str = "ProtoMessage{"; switch ((ProtoPayloadType)msg.PayloadType) { case ProtoPayloadType.HeartbeatEvent: _ = ProtoHeartbeatEvent.Parser.ParseFrom(msg.Payload); _str += "Heartbeat"; break; case ProtoPayloadType.ErrorRes: var _err = ProtoErrorRes.Parser.ParseFrom(msg.Payload); _str += "ErrorResponse{errorCode:" + _err.ErrorCode + (_err.HasDescription ? ", description:" + _err.Description : "") + "}"; break; default: _str += GetApiMessageText(msg); break; } _str += (msg.HasClientMsgId ? ", clientMsgId:" + msg.ClientMsgId : "") + "}"; return(_str); }
/// <summary> /// Disband an army /// </summary> /// <param name="armyID">ID of army to disband</param> public void DisbandArmy(string armyID) { ProtoMessage disband = new ProtoMessage(); disband.ActionType = Actions.DisbandArmy; disband.Message = armyID; net.Send(disband); }
/// <summary> /// Maintain the army indicated by the army ID /// </summary> /// <param name="armyID">Army to maintain</param> public void MaintainArmy(string armyID) { ProtoMessage maintain = new ProtoMessage(); maintain.ActionType = Actions.MaintainArmy; maintain.Message = armyID; net.Send(maintain); }
/// <summary> /// End the siege /// </summary> /// <param name="siegeID">ID of siege</param> public void EndSiege(string siegeID) { ProtoMessage end = new ProtoMessage(); end.ActionType = Actions.EndSiege; end.Message = siegeID; net.Send(end); }
/// <summary> /// Conduct a reduction round during this siege /// </summary> /// <param name="siegeID">ID of siege</param> public void ReductionRound(string siegeID) { ProtoMessage reduce = new ProtoMessage(); reduce.ActionType = Actions.SiegeRoundReduction; reduce.Message = siegeID; net.Send(reduce); }
/// <summary> /// Conduct a negotiation round during this siege /// </summary> /// <param name="siegeID">ID of siege</param> public void NegotiationRound(string siegeID) { ProtoMessage negotiate = new ProtoMessage(); negotiate.ActionType = Actions.SiegeRoundNegotiate; negotiate.Message = siegeID; net.Send(negotiate); }
/// <summary> /// Conduct a storm round during this siege /// </summary> /// <param name="siegeID">ID of siege</param> public void StormRound(string siegeID) { ProtoMessage storm = new ProtoMessage(); storm.ActionType = Actions.SiegeRoundStorm; storm.Message = siegeID; net.Send(storm); }
/// <summary> /// Besiege the fief your army is currently in /// </summary> /// <param name="armyID">ID of army who will be besieging</param> public void Besiege(string armyID) { ProtoMessage besiege = new ProtoMessage(); besiege.ActionType = Actions.BesiegeFief; besiege.Message = armyID; net.Send(besiege); }
public static void Eval(UserObject userobj, ProtoMessage msg, AresTCPPacketReader packet) { switch (msg) { case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_ADD_TAGS: ProcessAddCustomTag(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_REM_TAGS: ProcessRemCustomTag(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_FONT: ProcessCustomFont(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_SUPPORTED: ProcessVCSupported(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_FIRST: ProcessVCFirst(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_FIRST_TO: ProcessVCFirstTo(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_CHUNK: ProcessVCChunk(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_CHUNK_TO: ProcessVCChunkTo(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_VC_IGNORE: ProcessVCIgnore(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_SUPPORTS_CUSTOM_EMOTES: ProcessSupportsCustomEmotes(userobj); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_EMOTES_UPLOAD_ITEM: ProcessCustomEmoteUpload(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_CUSTOM_EMOTE_DELETE: ProcessCustomEmoteDelete(userobj, packet); break; } }