void SendCreateFaction(long founderId, string factionTag, string factionName, string factionDesc, string factionPrivate) { var msg = new AddFactionMsg(); msg.FounderId = founderId; msg.FactionTag = factionTag; msg.FactionName = factionName; msg.FactionDescription = factionDesc; msg.FactionPrivateInfo = factionPrivate; Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
void SendCreateFaction(long founderId, string factionTag, string factionName, string factionDesc, string factionPrivate) { var msg = new AddFactionMsg(); msg.FounderId = founderId; msg.FactionTag = factionTag; msg.FactionName = factionName; msg.FactionDescription = factionDesc; msg.FactionPrivateInfo = factionPrivate; MyMultiplayer.RaiseStaticEvent(s => MyFactionCollection.CreateFactionRequest, msg); }
/// <summary> /// Creates faction on server and sends message to client to create one there. If faction definition is provided than faction will be created from definition and /// faction name, description and private info will be taken from definition. /// </summary> /// <param name="founderId">Founder id</param> /// <param name="factionTag">Faction tag</param> /// <param name="factionName">Faction name</param> /// <param name="description">Faction Description</param> /// <param name="privateInfo">Private info</param> /// <param name="factionDef">Optional: faction definition.</param> private static void CreateFactionServer(long founderId, string factionTag, string factionName, string description, string privateInfo, MyFactionDefinition factionDef = null) { Debug.Assert(Sync.IsServer, "Faction ID can only be allocated on the server!"); if (!Sync.IsServer) { return; } long factionId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.FACTION); var faction = MySession.Static.Factions.TryGetFactionById(factionId); var senderFaction = MySession.Static.Factions.TryGetPlayerFaction(founderId); if (senderFaction == null && faction == null && !MySession.Static.Factions.FactionTagExists(factionTag) && !MySession.Static.Factions.FactionNameExists(factionName) && Sync.Players.HasIdentity(founderId)) { bool createFromDef = factionDef == null ? false : true; if (createFromDef) { CreateFactionInternal(founderId, factionId, factionDef); } else { CreateFactionInternal(founderId, factionId, factionTag, factionName, description, privateInfo); } AddFactionMsg newMsg = new AddFactionMsg(); newMsg.FactionId = factionId; newMsg.FounderId = founderId; newMsg.FactionTag = factionTag; newMsg.FactionName = factionName; newMsg.FactionDescription = description; newMsg.FactionPrivateInfo = privateInfo; newMsg.CreateFromDefinition = createFromDef; Sync.Layer.SendMessageToAll(ref newMsg, MyTransportMessageEnum.Success); // Call myself. SetDefaultFactionStates(factionId); // Call everyone else. MyMultiplayer.RaiseStaticEvent(x => SetDefaultFactionStates, factionId); } }
static void CreateFactionSuccess(ref AddFactionMsg msg, MyNetworkClient sender) { if (msg.CreateFromDefinition) { var factionDef = MyDefinitionManager.Static.TryGetFactionDefinition(msg.FactionTag); if (factionDef == null) { Debug.Assert(false, "Could not find a faction definition for the tag " + msg.FactionTag); return; } CreateFactionInternal(msg.FounderId, msg.FactionId, factionDef); } else { CreateFactionInternal(msg.FounderId, msg.FactionId, msg.FactionTag, msg.FactionName, msg.FactionDescription, msg.FactionPrivateInfo); } }
static void CreateFactionRequest(ref AddFactionMsg msg, MyNetworkClient sender) { msg.FactionId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.FACTION); var faction = MySession.Static.Factions.TryGetFactionById(msg.FactionId); var senderFaction = MySession.Static.Factions.TryGetPlayerFaction(msg.FounderId); if (senderFaction == null && faction == null && !MySession.Static.Factions.FactionTagExists(msg.FactionTag) && !MySession.Static.Factions.FactionNameExists(msg.FactionName) && Sync.Players.HasIdentity(msg.FounderId)) { Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success); } /*else * { * Sync.Layer.SendMessage(ref msg, SteamSDK.sender.SteamUserId, MyTransportMessageEnum.Failure); * }*/ }
static void CreateFactionSuccess(ref AddFactionMsg msg, MyNetworkClient sender) { MySession.Static.Factions.AddPlayerToFaction(msg.FounderId, msg.FactionId); MySession.Static.Factions.Add(new MyFaction( id: msg.FactionId, tag: msg.FactionTag, name: msg.FactionName, desc: msg.FactionDescription, privateInfo: msg.FactionPrivateInfo, creatorId: msg.FounderId)); foreach (var entry in MySession.Static.Factions) { var faction = entry.Value; faction.CancelJoinRequest(msg.FounderId); } var handler = MySession.Static.Factions.FactionCreated; if (handler != null) { handler(msg.FactionId); } }
static void CreateFactionRequest(ref AddFactionMsg msg, MyNetworkClient sender) { CreateFactionServer(msg.FounderId, msg.FactionTag, msg.FactionName, msg.FactionDescription, msg.FactionPrivateInfo); }
static void CreateFactionRequest(AddFactionMsg msg) { CreateFactionServer(msg.FounderId, msg.FactionTag, msg.FactionName, msg.FactionDescription, msg.FactionPrivateInfo); }