/// <summary> /// Adds a(n) <see cref="ISession"/>. /// </summary> /// <param name="addSession"></param> private void HandleAddSession(AddSession addSession) { ISession existingSession; // making sure we dont already have a session with the same session id if (sessions.TryGetValue(addSession.SessionId, out existingSession)) { // since adding sessions is controlled by the master rather than the client // we will not notify the client rather throw out an error Logger.ErrorFormat("[HandleAddSession]: Destroying existing Session (Name={0})", existingSession.Name); // destroy the exisiting session // we dont need to destroy the requested session since they both have the same session id, both (if possible) will be destroyed existingSession.Destroy(DestroySessionReason.KickedByExistingSession); return; } ISession session = new SocialSession(addSession.SessionId, addSession.CharacterName, this, social); // if a lock wait time is used (not -1) use a while loop to counter lock timeouts if (!sessions.Add(addSession.SessionId, session)) { // this will not happen but Murphy's law states otherwise Logger.ErrorFormat("[HandleAddSession]: Session (Name={0}) cannot be added", addSession.CharacterName); session.Destroy(DestroySessionReason.KickedByServer); } }
public void Run() { var map = new ConcurrentStorageMap <Guid, string>(-1); var t1 = new Thread(o => { for (var i = 0; i < 10; i++) { map.Add(Guid.NewGuid(), o + i.ToString()); } }); t1.Start("one"); t1.Join(); var t2 = new Thread(o => { for (var i = 0; i < 10; i++) { map.Add(Guid.NewGuid(), o + i.ToString()); } }); t2.Start("two"); t2.Join(); var t3 = new Thread(o => { for (var i = 0; i < 10; i++) { map.Add(Guid.NewGuid(), o + i.ToString()); } }); t3.Start("three"); t3.Join(); foreach (var value in map) { Console.WriteLine(value); } }
/// <summary> /// Adds a(n) <see cref="IWorld"/> to the social /// </summary> public bool AddWorld(short worldId, IWorld world) { // using a while loop for the lock-timeout while (!worlds.Add(worldId, world)) { IWorld existingWorld; if (worlds.TryGetValue(worldId, out existingWorld)) { return(false); } } return(true); }
/// <summary> /// Creates a new <see cref="MmoZone"/>. /// </summary> public MmoZone CreateZone(short id, string name, Bounds zoneBounds, Vector3 tileDimentions, ZoneDescription zoneDescription) { MmoZone existingZone; if (zones.TryGetValue(id, out existingZone)) { return(existingZone); } // locking to update the bounds lock (zones) { this.bounds = this.bounds.Size != Vector3.Zero ? this.bounds.UnionWith(zoneBounds) : zoneBounds; var newZone = new MmoZone(this, id, name, zoneBounds, tileDimentions, zoneDescription, configuration); zones.Add(id, newZone); return(newZone); } }
/// <summary> /// Adds a(n) <see cref="ISession"/>. /// </summary> /// <param name="addSession"></param> private void HandleAddSession(AddSession addSession) { ISession existingSession; // making sure we dont already have a session with the same session id if (sessions.TryGetValue(addSession.SessionId, out existingSession)) { // since adding sessions is controlled by the master rather than the client // we will not notify the client rather throw out an error Logger.ErrorFormat("[HandleAddSession]: Destroying existing Session (Name={0})", existingSession.Name); // destroy the exisiting session // we dont need to destroy the requested session since they both have the same session id, both (if possible) will be destroyed existingSession.Destroy(DestroySessionReason.KickedByExistingSession); return; } ISession session = new WorldSession(addSession.SessionId, addSession.CharacterName, this, world, addSession.IsTransfer); // if a lock wait time is used (not -1) use a while loop to counter lock timeouts if (!sessions.Add(addSession.SessionId, session)) { // this will not happen but Murphy's law states otherwise Logger.ErrorFormat("[HandleAddSession]: Session (Name={0}) cannot be added", addSession.CharacterName); session.Destroy(DestroySessionReason.KickedByServer); return; } // notifying the master to update the state so the client can start sending messages this.SendOperationRequest( new OperationRequest((byte)ServerOperationCode.AckClientPlayerTransferWorld, new AckClientPlayerEnterWorld { SessionId = session.SessionId, }), new SendParameters()); }
/// <summary> /// Adds an item to the cache /// </summary> public bool AddItem(MmoObject mmoObject) { var guid = mmoObject.Guid; return(objects.Add(guid.Type, guid.Id, mmoObject)); }