static void FactionStateChangeRequest(ref FactionStateChangeMsg msg, MyNetworkClient sender) { var fromFaction = MySession.Static.Factions.TryGetFactionById(msg.FromFactionId); var toFaction = MySession.Static.Factions.TryGetFactionById(msg.ToFactionId); if (fromFaction != null && toFaction != null && MySession.Static.Factions.CheckFactionStateChange(msg.Action, msg.FromFactionId, msg.ToFactionId, msg.PlayerId, msg.SenderId)) { if ((msg.Action == MyFactionStateChange.FactionMemberKick || msg.Action == MyFactionStateChange.FactionMemberLeave) && fromFaction.Members.Count() == 1) { msg.Action = MyFactionStateChange.RemoveFaction; } else if (msg.Action == MyFactionStateChange.FactionMemberSendJoin && (toFaction.AutoAcceptMember || MySession.Static.Settings.ScenarioEditMode)) { msg.Action = MyFactionStateChange.FactionMemberAcceptJoin; msg.SenderId = 0; // no need to check who accepted this } else if (msg.Action == MyFactionStateChange.SendPeaceRequest && toFaction.AutoAcceptPeace) { msg.Action = MyFactionStateChange.AcceptPeace; msg.SenderId = 0; // no need to check who accepted this } FactionStateChangeSuccess(ref msg, sender); Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); } /*else * { * Sync.Layer.SendMessage(ref msg, SteamSDK.sender.SteamUserId, MyTransportMessageEnum.Failure); * }*/ }
static void SendFactionChange(MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId) { var msg = new FactionStateChangeMsg(); msg.Action = action; msg.FromFactionId = fromFactionId; msg.ToFactionId = toFactionId; msg.PlayerId = playerId; msg.SenderId = MySession.LocalPlayerId; Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
static void FactionStateChangeRequest(ref FactionStateChangeMsg msg, MyNetworkClient sender) { var fromFaction = MySession.Static.Factions.TryGetFactionById(msg.FromFactionId); var toFaction = MySession.Static.Factions.TryGetFactionById(msg.ToFactionId); if (fromFaction != null && toFaction != null && MySession.Static.Factions.CheckFactionStateChange(msg.Action, msg.FromFactionId, msg.ToFactionId, msg.PlayerId, msg.SenderId)) { if ((msg.Action == MyFactionStateChange.FactionMemberKick || msg.Action == MyFactionStateChange.FactionMemberLeave) && fromFaction.Members.Count() == 1) { msg.Action = MyFactionStateChange.RemoveFaction; } else if (msg.Action == MyFactionStateChange.FactionMemberSendJoin) { bool canAccept = MySession.Static.Settings.ScenarioEditMode; if (toFaction.AutoAcceptMember) { canAccept = true; if (!toFaction.AcceptHumans) { // Check, whether the requesting player is human or bot var humanPlayer = sender.FirstPlayer; if (humanPlayer != null && humanPlayer.Identity.IdentityId == msg.PlayerId) { // You are a human. We dont like human! canAccept = false; msg.Action = MyFactionStateChange.FactionMemberCancelJoin; } } } if (canAccept) { msg.Action = MyFactionStateChange.FactionMemberAcceptJoin; msg.SenderId = 0; // no need to check who accepted this } } else if (msg.Action == MyFactionStateChange.SendPeaceRequest && toFaction.AutoAcceptPeace) { msg.Action = MyFactionStateChange.AcceptPeace; msg.SenderId = 0; // no need to check who accepted this } FactionStateChangeSuccess(ref msg, sender); Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); } /*else * { * Sync.Layer.SendMessage(ref msg, SteamSDK.sender.SteamUserId, MyTransportMessageEnum.Failure); * }*/ }
static void FactionStateChangeSuccess(ref FactionStateChangeMsg msg, MyNetworkClient sender) { var fromFaction = MySession.Static.Factions.TryGetFactionById(msg.FromFactionId); var toFaction = MySession.Static.Factions.TryGetFactionById(msg.ToFactionId); if (fromFaction != null && toFaction != null) { MySession.Static.Factions.ApplyFactionStateChange(msg.Action, msg.FromFactionId, msg.ToFactionId, msg.PlayerId, msg.SenderId); var handler = MySession.Static.Factions.FactionStateChanged; if (handler != null) { handler(msg.Action, msg.FromFactionId, msg.ToFactionId, msg.PlayerId, msg.SenderId); } } }