// // Event handler for HttpApplication.AcquireRequestState // private void OnAcquireRequestState(object source, EventArgs args) { acquireCalled = true; HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; bool isNew = false; string sessionID; SessionItem sessionData = null; bool supportSessionIDReissue = true; pSessionIDManager.InitializeRequest(context, false, out supportSessionIDReissue); sessionID = pSessionIDManager.GetSessionID(context); if (sessionID != null) { try { pHashtableLock.EnterReadLock(); sessionData = (SessionItem)pSessionItems[sessionID]; if (sessionData != null) { sessionData.Expires = DateTime.Now.AddMinutes(pTimeout); } } finally { pHashtableLock.ExitReadLock(); } } else { bool redirected, cookieAdded; sessionID = pSessionIDManager.CreateSessionID(context); pSessionIDManager.SaveSessionID(context, sessionID, out redirected, out cookieAdded); if (redirected) { return; } } if (sessionData == null) { // Identify the session as a new session state instance. Create a new SessionItem // and add it to the local Hashtable. isNew = true; sessionData = new SessionItem(); sessionData.Items = new SessionStateItemCollection(); sessionData.StaticObjects = SessionStateUtility.GetSessionStaticObjects(context); sessionData.Expires = DateTime.Now.AddMinutes(pTimeout); try { pHashtableLock.EnterWriteLock(); pSessionItems[sessionID] = sessionData; } finally { pHashtableLock.ExitWriteLock(); } } // Add the session data to the current HttpContext. SessionStateUtility.AddHttpSessionStateToContext(context, new HttpSessionStateContainer(sessionID, sessionData.Items, sessionData.StaticObjects, pTimeout, isNew, pCookieMode, SessionStateMode.Custom, false)); // Execute the Session_OnStart event for a new session. if (isNew && Start != null) { Start(this, EventArgs.Empty); } }
private Session Create(Guid guid) { SessionItem item = new SessionItem(guid); sessions.Add(guid,item); return item.Session; }
public void Save() { if(Board.master != null){ // Save Pictures pictures = new List<SessionPicture>(); foreach(Picture picture in Board.master.pictures){ SessionPicture sessionPicture = new SessionPicture(); sessionPicture.position = picture.position; sessionPicture.rotation = picture.rotation; sessionPicture.subject = picture.subject; pictures.Add(sessionPicture); } // Save Pins pins = new List<SessionPin>(); foreach(Pin pin in Board.master.pins){ SessionPin sessionPin = new SessionPin(); sessionPin.position = pin.position; sessionPin.colour = pin.colour; pins.Add(sessionPin); } // Save PostIts postits = new List<SessionPostIt>(); foreach(PostIt postit in Board.master.postits){ SessionPostIt sessionPostIt = new SessionPostIt(); sessionPostIt.position = postit.position; sessionPostIt.rotation = postit.rotation; sessionPostIt.message = postit.simpleText; postits.Add(sessionPostIt); } // Save Strings strings = new List<SessionString>(); foreach(String currentString in Board.master.strings){ SessionString sessionString = new SessionString(); sessionString.startPoint = currentString.startPoint; sessionString.endPoint = currentString.endPoint; strings.Add(sessionString); } } // Save Time/Events if(TimeManager.master){ day = TimeManager.master.currentDayReference; time = TimeManager.master.time; completedEvents = EventManager.completedEvents; failedEvents = EventManager.failedEvents; dayEvents = new Dictionary<string,List<string>>(); foreach (Day currentDay in TimeManager.master.days){ List<string> eventList = new List<string>(); foreach (Event eventCheck in currentDay.events){ if(eventCheck.eventHappened == true){ eventList.Add(eventCheck.eventName); } } dayEvents.Add(currentDay.dayName, eventList); } } // Save Items if(Inventory.master){ items = new Dictionary<string, SessionItem>(); foreach(KeyValuePair<string,Item> item in Inventory.master.itemDictionary){ SessionItem sessionItem = new SessionItem(); sessionItem.position = item.Value.position; sessionItem.location = item.Value.currentLocation.id; if(item.Value.owner != null){ sessionItem.owner = item.Value.owner.id; } else { sessionItem.owner = null; } if(item.Value.holder != null){ sessionItem.holder = item.Value.holder.id; } else { sessionItem.holder = null; } sessionItem.health = item.Value.health; sessionItem.uses = item.Value.uses; sessionItem.cost= item.Value.cost; sessionItem.power = item.Value.power; sessionItem.range = item.Value.range; sessionItem.state = item.Value.state; items.Add(item.Value.id, sessionItem); } } // Save Locations if(Map.master){ locations = new Dictionary<string, SessionLocation>(); foreach (string key in Map.master.locationDictionary.Keys){ Location location = Map.master.locationDictionary[key]; SessionLocation sessionLocation = new SessionLocation(); sessionLocation.accessable = location.accessable; if(location.owner != null){ sessionLocation.owner = location.owner.name; } else { sessionLocation.owner = null; } sessionLocation.state = location.state; locations.Add(location.id, sessionLocation); } } // Save People if(Population.master){ people = new Dictionary<string, SessionPerson>(); foreach(KeyValuePair<string,Person> person in Population.master.peopleDictionary){ SessionPerson sessionPerson = new SessionPerson(); sessionPerson.position = person.Value.transform.position; sessionPerson.location = person.Value.currentLocation.id; sessionPerson.health = person.Value.health; sessionPerson.energy = person.Value.energy; sessionPerson.hunger = person.Value.hunger; sessionPerson.money = person.Value.money; sessionPerson.power = person.Value.power; sessionPerson.speed = person.Value.speed; sessionPerson.range = person.Value.range; sessionPerson.state = person.Value.state; sessionPerson.emotion = person.Value.emotion; sessionPerson.reputations = new Dictionary<string, float>(); foreach(Person key in person.Value.reputation.reputations.Keys){ sessionPerson.reputations.Add(key.id, person.Value.reputation.reputations[key]); } people.Add(person.Value.id, sessionPerson); } } //Save Conversations if(ConversationManager.master){ conversations = new List<SessionConversation>(); foreach(Conversation _conversation in ConversationManager.master.conversations){ SessionConversation sessionConversation = new SessionConversation(); sessionConversation.id = _conversation.conversationReference; foreach(Person _participant in _conversation.participants){ string id = _participant.id; sessionConversation.participants.Add(id); } sessionConversation.lineReference = _conversation.currentLineRef; sessionConversation.currentTime = _conversation.currentTime; conversations.Add(sessionConversation); } } }
/// <summary> /// Initializes a new instance of the <see cref="MockHttpContext"/> class using the specified application path and virtual directory. /// </summary> /// <param name="applicationPath"></param> /// <param name="virtualDirectory"></param> /// <param name="page"></param> /// <param name="query"></param> public MockHttpContext(string applicationPath, string virtualDirectory, string page, string query) { if (String.IsNullOrWhiteSpace(applicationPath)) { throw new ArgumentException("Application path is empty!", "applicationPath"); } if (String.IsNullOrWhiteSpace(virtualDirectory)) { throw new ArgumentException("Virtual directory path is empty!", "virtualDirectory"); } _applicationPath = applicationPath; _virtualDirectory = virtualDirectory; _currentContext = HttpContext.Current; if (null == HttpContext.Current) { AppDomain.CurrentDomain.SetData(".appDomain", "*"); AppDomain.CurrentDomain.SetData(".appPath", applicationPath); AppDomain.CurrentDomain.SetData(".appVPath", virtualDirectory); AppDomain.CurrentDomain.SetData(".hostingVirtualPath", virtualDirectory); AppDomain.CurrentDomain.SetData(".hostingInstallDir", HttpRuntime.AspInstallDirectory); TextWriter tw = new StringWriter(); var simpleWorkerRequest = new SimpleWorkerRequest(page, query, tw); HttpWorkerRequest wr = simpleWorkerRequest; HttpContext.Current = new HttpContext(wr); _sessionData = new SessionItem(); _sessionData.Items = new SessionStateItemCollection(); _sessionData.StaticObjects = SessionStateUtility.GetSessionStaticObjects(HttpContext.Current); _sessionID = Guid.NewGuid().ToString(); _ioLock.EnterWriteLock(); try { _sessionItems.Add(_sessionID, _sessionData); } finally { _ioLock.ExitWriteLock(); } var container = new HttpSessionStateContainer(_sessionID, _sessionData.Items, _sessionData.StaticObjects, 10, true, _cookieMode, SessionStateMode.Custom, false); SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, container); } }
public async Task <(SessionItem, IEnumerable <SessionItem>, JToken)> GetGameList() { using (var http = new HttpClient()) { var res = await http.GetStringAsync(queryUrl).ConfigureAwait(false); var gamelist = JsonConvert.DeserializeObject <BZCCRaknetData>(res); SessionItem DefaultSession = new SessionItem() { Type = "listen", SpectatorPossible = false, // unless we add special mod support //SpectatorSeperate = false, }; List <SessionItem> Sessions = new List <SessionItem>(); foreach (var raw in gamelist.GET) { SessionItem game = new SessionItem(); game.Name = raw.Name; if (!string.IsNullOrWhiteSpace(raw.MOTD)) { game.Message = raw.MOTD; } game.PlayerCount = raw.CurPlayers; game.PlayerMax = raw.MaxPlayers; game.Level.Add("MapFile", raw.MapFile); game.Level.Add("MapID", GameID + @":" + (raw.Mods?.FirstOrDefault() ?? @"0") + @":" + raw.MapFile); game.Status.Add("Locked", raw.Locked); game.Status.Add("Passworded", raw.Passworded); if (raw.ServerInfoMode.HasValue) { switch (raw.ServerInfoMode) { case 1: game.Status.Add("State", @"Lobby"); break; case 2: game.Status.Add("State", @"Loading"); // guess break; case 3: game.Status.Add("State", @"InGame"); break; case 4: game.Status.Add("State", @"Over"); // guess break; } } if ((raw.Mods?.Length ?? 0) > 0) { game.Attributes.Add("Mods", JArray.FromObject(raw.Mods)); } if (!string.IsNullOrWhiteSpace(raw.v)) { game.Attributes.Add("Version", raw.v); } if (raw.TPS.HasValue && raw.TPS > 0) { game.Attributes.Add("TPS", raw.TPS); } if (raw.MaxPing.HasValue && raw.MaxPing > 0) { game.Attributes.Add("MaxPing", raw.MaxPing); } if (raw.TimeLimit.HasValue && raw.TimeLimit > 0) { game.Attributes.Add("TimeLimit", raw.TimeLimit); } if (raw.KillLimit.HasValue && raw.KillLimit > 0) { game.Attributes.Add("KillLimit", raw.KillLimit); } if (!string.IsNullOrWhiteSpace(raw.t)) { switch (raw.t) { case "0": game.Attributes.Add("NAT", $"NONE"); /// Works with anyone break; case "1": game.Attributes.Add("NAT", $"FULL CONE"); /// Accepts any datagrams to a port that has been previously used. Will accept the first datagram from the remote peer. break; case "2": game.Attributes.Add("NAT", $"ADDRESS RESTRICTED"); /// Accepts datagrams to a port as long as the datagram source IP address is a system we have already sent to. Will accept the first datagram if both systems send simultaneously. Otherwise, will accept the first datagram after we have sent one datagram. break; case "3": game.Attributes.Add("NAT", $"PORT RESTRICTED"); /// Same as address-restricted cone NAT, but we had to send to both the correct remote IP address and correct remote port. The same source address and port to a different destination uses the same mapping. break; case "4": game.Attributes.Add("NAT", $"SYMMETRIC"); /// A different port is chosen for every remote destination. The same source address and port to a different destination uses a different mapping. Since the port will be different, the first external punchthrough attempt will fail. For this to work it requires port-prediction (MAX_PREDICTIVE_PORT_RANGE>1) and that the router chooses ports sequentially. break; case "5": game.Attributes.Add("NAT", $"UNKNOWN"); /// Hasn't been determined. NATTypeDetectionClient does not use this, but other plugins might break; case "6": game.Attributes.Add("NAT", $"DETECTION IN PROGRESS"); /// In progress. NATTypeDetectionClient does not use this, but other plugins might break; case "7": game.Attributes.Add("NAT", $"SUPPORTS UPNP"); /// Didn't bother figuring it out, as we support UPNP, so it is equivalent to NAT_TYPE_NONE. NATTypeDetectionClient does not use this, but other plugins might break; default: game.Attributes.Add("NAT", $"[" + raw.t + "]"); break; } } switch (raw.proxySource) { case "Rebellion": game.Attributes.Add("List", $"Rebellion"); break; default: game.Attributes.Add("List", $"IonDriver"); break; } bool m_TeamsOn = false; bool m_OnlyOneTeam = false; switch (raw.GameType) { case 0: game.Attributes.Add("Type", $"All"); break; case 1: { int GetGameModeOutput = raw.GameSubType.Value % (int)GameMode.GAMEMODE_MAX; // extract if we are team or not int detailed = raw.GameSubType.Value / (int)GameMode.GAMEMODE_MAX; // ivar7 bool RespawnSameRace = (detailed & 256) == 256; bool RespawnAnyRace = (detailed & 512) == 512; game.Attributes.Add("Respawn", RespawnSameRace ? "Race" : RespawnAnyRace ? "Any" : "One"); detailed = (detailed & 0xff); switch ((GameMode)GetGameModeOutput) { case GameMode.GAMEMODE_TEAM_DM: case GameMode.GAMEMODE_TEAM_KOTH: case GameMode.GAMEMODE_TEAM_CTF: case GameMode.GAMEMODE_TEAM_LOOT: case GameMode.GAMEMODE_TEAM_RACE: m_TeamsOn = true; break; case GameMode.GAMEMODE_DM: case GameMode.GAMEMODE_KOTH: case GameMode.GAMEMODE_CTF: case GameMode.GAMEMODE_LOOT: case GameMode.GAMEMODE_RACE: default: m_TeamsOn = false; break; } switch (detailed) // first byte of ivar7? might be all of ivar7 // Deathmatch subtype (0 = normal; 1 = KOH; 2 = CTF; add 256 for random respawn on same race, or add 512 for random respawn w/o regard to race) { case 0: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"DM"); break; case 1: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"KOTH"); break; case 2: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"CTF"); break; case 3: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"Loot"); break; case 4: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"DM [RESERVED]"); break; case 5: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"Race"); break; case 6: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"Race (Vehicle Only)"); break; case 7: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"DM (Vehicle Only)"); break; default: game.Level.Add("GameMode", (m_TeamsOn ? "TEAM " : String.Empty) + $"DM [UNKNOWN {raw.GameSubType}]"); break; } } break; case 2: { int GetGameModeOutput = raw.GameSubType.Value % (int)GameMode.GAMEMODE_MAX; // extract if we are team or not switch ((GameMode)GetGameModeOutput) { case GameMode.GAMEMODE_TEAM_STRAT: game.Level.Add("GameMode", $"TEAM STRAT"); m_TeamsOn = true; m_OnlyOneTeam = false; break; case GameMode.GAMEMODE_STRAT: game.Level.Add("GameMode", $"STRAT"); m_TeamsOn = false; m_OnlyOneTeam = false; break; case GameMode.GAMEMODE_MPI: game.Level.Add("GameMode", $"MPI"); m_TeamsOn = true; m_OnlyOneTeam = true; break; default: game.Level.Add("GameMode", $"STRAT [UNKNOWN {GetGameModeOutput}]"); break; } } break; case 3: // impossible, BZCC limits to 0-2 game.Attributes.Add("Type", $"MPI [Invalid]"); break; } if (!string.IsNullOrWhiteSpace(raw.d)) { game.Attributes.Add("ModHash", raw.d); // base64 encoded CRC32 } foreach (var dr in raw.pl) { PlayerItem player = new PlayerItem(); player.Name = dr.Name; if ((dr.Team ?? 255) != 255) // 255 means not on a team yet? could be understood as -1 { player.Team = new PlayerTeam(); if (m_TeamsOn) { if (!m_OnlyOneTeam) { if (dr.Team >= 1 && dr.Team <= 5) { player.Team.ID = 1; } if (dr.Team >= 6 && dr.Team <= 10) { player.Team.ID = 2; } if (dr.Team == 1 || dr.Team == 6) { player.Team.Leader = true; } } } player.Team.SubTeam = new PlayerTeam() { ID = dr.Team.Value }; player.GetIDData("Slot").Add("ID", dr.Team); } if (dr.Kills.HasValue) { player.Stats.Add("Kills", dr.Kills); } if (dr.Deaths.HasValue) { player.Stats.Add("Deaths", dr.Deaths); } if (dr.Score.HasValue) { player.Stats.Add("Score", dr.Score); } if (!string.IsNullOrWhiteSpace(dr.PlayerID)) { player.GetIDData("BZRNet").Add("ID", dr.PlayerID); switch (dr.PlayerID[0]) { case 'S': { player.GetIDData("Steam").Add("Raw", dr.PlayerID.Substring(1)); try { ulong playerID = 0; if (ulong.TryParse(dr.PlayerID.Substring(1), out playerID)) { player.GetIDData("Steam").Add("ID", playerID); PlayerSummaryModel playerData = await steamInterface.Users(playerID); player.GetIDData("Steam").Add("AvatarUrl", playerData.AvatarFullUrl); player.GetIDData("Steam").Add("Nickname", playerData.Nickname); player.GetIDData("Steam").Add("ProfileUrl", playerData.ProfileUrl); } } catch { } } break; case 'G': { player.GetIDData("Gog").Add("Raw", dr.PlayerID.Substring(1)); try { ulong playerID = 0; if (ulong.TryParse(dr.PlayerID.Substring(1), out playerID)) { //player.GetIDData("Gog").Add("LargeID", playerID); playerID &= 0x00ffffffffffffff; player.GetIDData("Gog").Add("ID", playerID); GogUserData playerData = await gogInterface.Users(playerID); player.GetIDData("Gog").Add("AvatarUrl", playerData.Avatar.sdk_img_184 ?? playerData.Avatar.large_2x ?? playerData.Avatar.large); player.GetIDData("Gog").Add("UserName", playerData.username); player.GetIDData("Gog").Add("ProfileUrl", $"https://www.gog.com/u/{playerData.username}"); } } catch { } } break; } } game.Players.Add(player); } if (raw.GameTimeMinutes.HasValue) { if (raw.GameTimeMinutes.Value == 255) // 255 appears to mean it maxed out? Does for currently playing. { game.Attributes.Add("GameTimeMinutes", "255+"); } else { game.Attributes.Add("GameTimeMinutes", raw.GameTimeMinutes); } } Sessions.Add(game); } return(DefaultSession, Sessions, JObject.Parse(res)); } }
public SessionItem Post(int id, [FromBody] SessionItem value) { return(value); }
/// <summary> /// roomid|content /// </summary> /// <param name="json"></param> public string SendMeesage(string json) { string[] strs = json.Split('|'); string roomId = strs[0]; string content = strs[1]; string userName = strs[2]; string userType = strs[3]; string userID = strs[4]; ConcurrentDictionary <PubgSession, SessionItem> dic = PubgSession.mOnLineConnections; if (dic == null || dic.Count == 0) { return("failture"); } //玩家的信息 if (userType.Equals("0")) { //获取该房间下的所有用户 List <Room_User> roomUsers = roomDao.SearchSingleGrounpCommon(roomId, int.Parse(userID)); //获取管理员 int AdminUser = roomDao.GetGrounpAdminByRoom(int.Parse(roomId)); //推送给所有队员 roomUsers.ForEach((item) => { foreach (PubgSession session in dic.Keys) { SessionItem sessionItem = null; dic.TryGetValue(session, out sessionItem); if (sessionItem != null && sessionItem.gpsItem != null && sessionItem.gpsItem.userId == item.user_id) { StartSendChatMessage(content, userName, session); } } }); //推送给该对的管理员 foreach (PubgSession session in dic.Keys) { SessionItem sessionItem = null; dic.TryGetValue(session, out sessionItem); if (sessionItem != null && sessionItem.gpsItem != null && sessionItem.gpsItem.userId == AdminUser) { StartSendChatMessage(content, userName, session); } } } //管理员 else { List <int> userIdList = roomDao.GetRoomUserListByAdmin(int.Parse(userID)); userIdList.ForEach((userId) => { foreach (PubgSession session in dic.Keys) { SessionItem sessionItem = null; dic.TryGetValue(session, out sessionItem); if (sessionItem != null && sessionItem.gpsItem != null && ( sessionItem.gpsItem.userId == userId)) { StartSendChatMessage(content, "系统管理员", session); } } }); } return("success"); }
internal void ExecuteGetItem(string id, bool exclusive, out byte[] itemBuffer, out long itemLength, out bool locked, out TimeSpan lockAge, out int lockCookie, out bool requiresInitialization) { ValidateIdLength(id); SqlCommand cmd; if (exclusive) { cmd = GetStateItemExclusive; } else { cmd = GetStateItem; } cmd.Parameters[0].Value = id; // @SessionId cmd.Parameters[1].Value = Convert.DBNull; // @Locked cmd.Parameters[2].Value = Convert.DBNull; // @LockAge cmd.Parameters[3].Value = Convert.DBNull; // @LockCookie cmd.Parameters[4].Value = Convert.DBNull; // @Initialized cmd.Parameters[5].Value = Convert.DBNull; // @Item List <SessionItem> buffers = null; long bufferLength = 0; // Read the data first, then the output parameters. using (SqlDataReader reader = SqlExecuteReaderWithRetry(cmd, CommandBehavior.SequentialAccess)) { try { if (reader.Read()) { buffers = new List <SessionItem>(); do { byte[] buffer = null; if (!s_itemBlockLookaside.TryPop(out buffer)) { buffer = new byte[ITEM_1_BLOCK_LENGTH]; } int index = reader.GetInt32(0); // SessionItemId long bytesRead = reader.GetBytes(1, 0, buffer, 0, buffer.Length); // Item var item = new SessionItem() { Id = index, BufferLength = (int)bytesRead, Buffer = buffer }; buffers.Add(item); bufferLength += item.BufferLength; }while (reader.Read()); } } catch (Exception e) { throw CreateHttpException(e); } } // Read the output parameters. locked = (bool)cmd.Parameters[1].Value; lockAge = TimeSpan.FromSeconds((int)cmd.Parameters[2].Value); lockCookie = (int)cmd.Parameters[3].Value; bool initialized = (bool)cmd.Parameters[4].Value; requiresInitialization = !initialized; if (locked) { itemBuffer = null; itemLength = 0; } else if (bufferLength == 0) { // Item is returned from the output parameter. object value; value = cmd.Parameters[5].Value; if (Convert.IsDBNull(value)) { itemBuffer = null; itemLength = 0; } else { itemBuffer = (byte[])value; itemLength = itemBuffer.LongLength; } } else { // Server does not return sorted rows due to performance. buffers.Sort(); itemBuffer = new byte[bufferLength]; itemLength = 0; for (int i = 0; i < buffers.Count; ++i) { long len = buffers[i].BufferLength; Buffer.BlockCopy(buffers[i].Buffer, 0, itemBuffer, (int)itemLength, (int)len); itemLength += len; s_itemBlockLookaside.Push(buffers[i].Buffer); } } }
public void SetItem(int Index, SessionItem Item) { List[Index] = Item; }
public void Add(SessionItem newItem) { List.Add(newItem); }
public bool addToList(SessionItem sess) { Session_List.Add(sess); return(true); }
public void Read() { // Load Time/Events Session.master.time = time; Session.master.day = currentDay; Session.master.completedEvents = completedEvents; Session.master.failedEvents = failedEvents; Session.master.dayEvents = new Dictionary<string, List<string>>(); foreach(DaySave day in days){ Session.master.dayEvents.Add(day.dayName, day.events); } //Load Locations Session.master.locations = new Dictionary<string, SessionLocation>(); foreach(LocationSave locationSave in mapSave){ SessionLocation sessionLocation = new SessionLocation(); sessionLocation.accessable = bool.Parse(locationSave.accessable); sessionLocation.owner = locationSave.owner; sessionLocation.state = locationSave.state; Session.master.locations.Add(locationSave.id, sessionLocation); } //Load People Session.master.people = new Dictionary<string, SessionPerson>(); foreach(PersonSave personSave in peopleSave){ SessionPerson sessionPerson = new SessionPerson(); sessionPerson.location = personSave.location; sessionPerson.position = new Vector3(personSave.position[0], personSave.position[1], personSave.position[2]); sessionPerson.health = personSave.health; sessionPerson.energy = personSave.energy; sessionPerson.hunger = personSave.hunger; sessionPerson.money = personSave.money; sessionPerson.power = personSave.power; sessionPerson.speed = personSave.speed; sessionPerson.range = personSave.range; sessionPerson.state = personSave.state; sessionPerson.emotion = personSave.emotion; sessionPerson.reputations = new Dictionary<string, float>(); for(int i=0; i<personSave.reputationPeople.Count; i++){ sessionPerson.reputations.Add(personSave.reputationPeople[i], personSave.reputations[i]); } Session.master.people.Add(personSave.id, sessionPerson); } // Load Items Session.master.items = new Dictionary<string, SessionItem>(); foreach(ItemSave itemSave in inventorySave){ SessionItem sessionItem = new SessionItem(); sessionItem.location = itemSave.location; sessionItem.position = new Vector3(itemSave.position[0], itemSave.position[1], itemSave.position[2]); sessionItem.owner = itemSave.owner; sessionItem.holder = itemSave.holder; sessionItem.properties = itemSave.properties; sessionItem.health = itemSave.health; sessionItem.uses = itemSave.uses; sessionItem.cost = itemSave.cost; sessionItem.power = itemSave.power; sessionItem.range = itemSave.range; sessionItem.state = itemSave.state; Session.master.items.Add(itemSave.name, sessionItem); } // Load Pictures Session.master.pictures = new List<SessionPicture>(); foreach(PictureSave pictureSave in picturesSave){ SessionPicture sessionPicture = new SessionPicture(); sessionPicture.position = new Vector3(pictureSave.position[0], pictureSave.position[1], pictureSave.position[2]); sessionPicture.subject = pictureSave.subject; sessionPicture.rotation = pictureSave.rotation; Session.master.pictures.Add(sessionPicture); } // Load Pins Session.master.pins = new List<SessionPin>(); foreach(PinSave pinSave in pinsSave){ SessionPin sessionPin = new SessionPin(); sessionPin.position = new Vector3(pinSave.position[0], pinSave.position[1], pinSave.position[2]); sessionPin.colour = new Color(pinSave.colour[0], pinSave.colour[1], pinSave.colour[2]); Session.master.pins.Add(sessionPin); } // Load PostIts Session.master.postits = new List<SessionPostIt>(); foreach(PostItSave postitSave in postitsSave){ SessionPostIt sessionPostIt = new SessionPostIt(); sessionPostIt.position = new Vector3(postitSave.position[0], postitSave.position[1], postitSave.position[2]); sessionPostIt.message = postitSave.message; sessionPostIt.rotation = postitSave.rotation; Session.master.postits.Add(sessionPostIt); } // Load Strings Session.master.strings = new List<SessionString>(); foreach(StringSave stringSave in stringsSave){ SessionString sessionString = new SessionString(); sessionString.startPoint = new Vector3(stringSave.startPoint[0], stringSave.startPoint[1], stringSave.startPoint[2]); sessionString.endPoint = new Vector3(stringSave.endPoint[0], stringSave.endPoint[1], stringSave.endPoint[2]); Session.master.strings.Add(sessionString); } }
public async Task <(SessionItem, IEnumerable <SessionItem>, JToken)> GetGameList() { using (var http = new HttpClient()) { var res = await http.GetStringAsync(queryUrl).ConfigureAwait(false); var gamelist = JsonConvert.DeserializeObject <Dictionary <string, Lobby> >(res); SessionItem DefaultSession = new SessionItem() { Type = "listen", SpectatorPossible = false, // unless we add special mod support //SpectatorSeperate = false, }; List <SessionItem> Sessions = new List <SessionItem>(); foreach (var raw in gamelist.Values) { if (raw.LobbyType != Lobby.ELobbyType.Game) { continue; } SessionItem game = new SessionItem(); game.Name = raw.Name; //if (!string.IsNullOrWhiteSpace(raw.MOTD)) // game.Message = raw.MOTD; game.PlayerCount = raw.userCount; game.PlayerMax = raw.PlayerLimit; game.Level.Add("MapFile", raw.MapFile); game.Level.Add("MapID", GameID + @":" + (raw.WorkshopID ?? @"0") + @":" + raw.MapFile); game.Status.Add("Locked", raw.isLocked); game.Status.Add("Passworded", raw.IsPassworded); game.Status.Add("State", raw.IsEnded ? "Over" : raw.IsLaunched ? "InGame" : "Lobby"); if (!string.IsNullOrWhiteSpace(raw.WorkshopID)) { game.Attributes.Add("Mod", raw.WorkshopID); } if (!string.IsNullOrWhiteSpace(raw.clientVersion)) { game.Attributes.Add("Version", raw.clientVersion); } if (raw.TimeLimit.HasValue && raw.TimeLimit > 0) { game.Attributes.Add("TimeLimit", raw.TimeLimit); } if (raw.KillLimit.HasValue && raw.KillLimit > 0) { game.Attributes.Add("KillLimit", raw.KillLimit); } if (raw.Lives.HasValue && raw.Lives.Value > 0) { game.Attributes.Add("Lives", raw.Lives.Value); } if (raw.SyncJoin.HasValue) { game.Attributes.Add("SyncJoin", raw.SyncJoin.Value); } if (raw.SatelliteEnabled.HasValue) { game.Attributes.Add("Satellite", raw.SatelliteEnabled.Value); } if (raw.BarracksEnabled.HasValue) { game.Attributes.Add("Barracks", raw.BarracksEnabled.Value); } if (raw.SniperEnabled.HasValue) { game.Attributes.Add("Sniper", raw.SniperEnabled.Value); } if (raw.SplinterEnabled.HasValue) { game.Attributes.Add("Splinter", raw.SplinterEnabled.Value); } foreach (var dr in raw.users.Values) { PlayerItem player = new PlayerItem(); player.Name = dr.name; if (dr.Team.HasValue) { player.Team = new PlayerTeam(); player.Team.ID = dr.Team; player.GetIDData("Slot").Add("ID", dr.Team); } player.Attributes.Add("Vehicle", dr.Vehicle); if (!string.IsNullOrWhiteSpace(dr.id)) { player.GetIDData("BZRNet").Add("ID", dr.id); switch (dr.id[0]) { case 'S': // dr.authType == "steam" { player.GetIDData("Steam").Add("Raw", dr.id.Substring(1)); try { ulong playerID = 0; if (ulong.TryParse(dr.id.Substring(1), out playerID)) { player.GetIDData("Steam").Add("ID", playerID); PlayerSummaryModel playerData = await steamInterface.Users(playerID); player.GetIDData("Steam").Add("AvatarUrl", playerData.AvatarFullUrl); player.GetIDData("Steam").Add("Nickname", playerData.Nickname); player.GetIDData("Steam").Add("ProfileUrl", playerData.ProfileUrl); } } catch { } } break; case 'G': { player.GetIDData("Gog").Add("Raw", dr.id.Substring(1)); try { ulong playerID = 0; if (ulong.TryParse(dr.id.Substring(1), out playerID)) { //player.GetIDData("Gog").Add("LargeID", playerID); playerID &= 0x00ffffffffffffff; player.GetIDData("Gog").Add("ID", playerID); GogUserData playerData = await gogInterface.Users(playerID); player.GetIDData("Gog").Add("AvatarUrl", playerData.Avatar.sdk_img_184 ?? playerData.Avatar.large_2x ?? playerData.Avatar.large); player.GetIDData("Gog").Add("UserName", playerData.username); player.GetIDData("Gog").Add("ProfileUrl", $"https://www.gog.com/u/{playerData.username}"); } } catch { } } break; } } game.Players.Add(player); } Sessions.Add(game); } return(DefaultSession, Sessions, JObject.Parse(res)); } }