private void onCreateCallback(DataLobby obj) { bool canAdded = false; if (!IsFiltered) { if (Lobbies != null && Lobbies.Find(item => item.roomId == obj.roomId) == null) { canAdded = true; } } else { List <DataLobby> listLobbyFilter = getListLobbyFilter(); if (listLobbyFilter.Contains(obj)) { canAdded = true; } } if (canAdded) { view.AddLobby(obj); Lobbies.Add(obj); } }
void OnLobbyDataUpdated(LobbyDataUpdate_t callback) { if (callback.Success == 1) //1 if success, 0 if failure { if (ManualLobbyDataCallbacks.ContainsKey(callback.SteamIDLobby)) { ManualLobbyDataCallbacks[callback.SteamIDLobby]?.Invoke(Lobby.FromSteam(client, callback.SteamIDLobby)); } //find the lobby that has been updated Lobby lobby = Lobbies.Find(x => x != null && x.LobbyID == callback.SteamIDLobby); //if this lobby isn't yet in the list of lobbies, we know that we should add it if (lobby == null) { if (requests.Contains(callback.SteamIDLobby)) { lobby = Lobby.FromSteam(client, callback.SteamIDLobby); Lobbies.Add(lobby); checkFinished(); } } //otherwise lobby data in general was updated and you should listen to see what changed if (requests.Contains(callback.SteamIDLobby)) { OnLobbiesUpdated?.Invoke(); } } }
public IActionResult Post([FromBody] NewLobbyRequest parameters) { if (parameters == null || parameters.token == null) { return(BadRequest(new Response("Wrong parameters", null))); } string token = parameters.token; string error = ""; if (!TokenManager.CheckUser(token)) { error = ErrorTypes.UNAUTH_USER_ERROR.ToString(); } Response resp; if (error == "") { Lobby newLobby = new Lobby(parameters.lobbyName); Lobbies.AddLobby(newLobby); int id = newLobby.Id; resp = new Response(error, new NewLobbyResponse(id)); } else { resp = new Response(error, null); } IActionResult res = Ok(resp); return(res); }
private void onUpdateCallback(DataLobby obj) { view.UpdateLobby(obj); DataLobby lob = Lobbies.Find(i => i.roomId == obj.roomId); lob = obj; }
public IActionResult Post([FromBody] TokenRequest parameters) { if (parameters == null || parameters.token == null) { return(BadRequest(new Response("Wrong parameters", null))); } string token = parameters.token; string error = ""; if (!TokenManager.CheckUser(token)) { error = ErrorTypes.UNAUTH_USER_ERROR.ToString(); } Response resp; if (error == "") { LobbiesResponse lobbiesResp = Lobbies.getLobbiesResponse(); resp = new Response(error, lobbiesResp); } else { resp = new Response(error, null); } IActionResult res = Ok(resp); return(res); }
/// <summary> /// Create a new lobbie named GroupName. /// </summary> /// <param name="GroupName">Lobby's name</param> public Lobby(string GroupName) { Drawers = new Dictionary <string, User>(); Canvas = new Canvas(); CanvasId = Canvas.Id; this.GroupName = GroupName; Lobbies.Add(GroupName, this); }
public IActionResult Post([FromBody] LobbyRequest parameters, [FromRoute] int id) { if (parameters == null || parameters.token == null) { return(BadRequest(new Response("Wrong parameters", null))); } string token = parameters.token; string error = ""; if (!TokenManager.CheckUser(token)) { error = ErrorTypes.UNAUTH_USER_ERROR.ToString(); } Response resp; if (error == "") { Lobby curLobby = Lobbies.GetLobby(id); Player p = TokenManager.GetPlayer(token); if (curLobby == null) { error = ErrorTypes.NONEXIST_LOBBY_ERROR.ToString(); resp = new Response(error, null); } else if (curLobby.GetPlayer(token) != null) { error = ErrorTypes.ALREADY_CONNECT_TO_LOBBY_ERROR.ToString(); resp = new Response(error, null); } else if (p.Status != PlayerStatus.Default) { error = ErrorTypes.ALREADY_CONNECT_TO_DIFF_LOBBY_ERROR.ToString(); resp = new Response(error, null); } else if (curLobby.Status != LobbyStatus.WaitingForPlayer) { error = ErrorTypes.FULL_LOBBY_ERROR.ToString(); resp = new Response(error, null); } else { curLobby.ConnectPlayer(p); resp = new Response(error, new LobbyResponse(curLobby)); } } else { resp = new Response(error, null); } IActionResult res = Ok(resp); return(res); }
public void LobbiesTest() { Lobby l = new Lobby("Lobby"); l.ConnectPlayer(new ProjectAstolfo.Model.Player("PlayerToken", "s")); Lobbies.AddLobby(l); var x = Lobbies.getLobbiesResponse(); Assert.AreEqual(x.lobbyResponses[0].name, "Lobby"); }
private void onDeleteCallback(DataLobby obj) { if (Lobbies != null) { DataLobby lob = Lobbies.Find(i => i.roomId == obj.roomId); if (lob != null) { view.RemoveLobby(obj); Lobbies.Remove(lob); } } }
private void NewConnect(string request, Socket socket) { Task.Run(() => { var userIp = ((IPEndPoint)socket.RemoteEndPoint).Address; var isBanned = Api.BannedIP.CheckBan(userIp.ToString()); if (isBanned) { Logger.Info($"[CONNECT]=> Игрок с IP:{userIp} не смог подключился к серверу, потому что его IP заблокирован."); var message = $"error;Ваш IP адрес заблокирован.;"; var data = Encoding.Unicode.GetBytes(message); socket.Send(data); try { Logger.Info($"Пользователь c IP:{userIp} отключен от сервера."); socket.Shutdown(SocketShutdown.Both); socket.Close(); socket.Dispose(); } catch (Exception e) { socket.Dispose(); Logger.Error($"Ошибка при отключении клиента от сервера: \n {e}"); } return; } Logger.Info($"[CONNECT]=> Игрок с IP:{userIp} подключился к серверу."); if (request.Split(";")[0] == "login") { var result = new Login(socket, this).Execute(request.Split(";").ToList()); if (result.Status) { var user = Api.Account.GetUserFromId(result.Id); var garage = Api.Garage.GetGarageFromId(result.Id); this.OnlineUsers.Add(user); var lobby = new Lobby(user, garage, socket, Logger); Lobbies.Add(lobby); lobby.LoadLobby(); lobby.UserDisconnected += ClientDisonnect; } else { var message = $"error;{result.Error};"; var data = Encoding.Unicode.GetBytes(message); socket.Send(data); } } }); }
void OnLobbyList(LobbyMatchList_t callback, bool error) { if (error) { return; } //how many lobbies matched uint lobbiesMatching = callback.LobbiesMatching; // lobbies are returned in order of closeness to the user, so add them to the list in that order for (int i = 0; i < lobbiesMatching; i++) { //add the lobby to the list of requests ulong lobby = client.native.matchmaking.GetLobbyByIndex(i); if (requests.Contains(lobby)) { continue; } requests.Add(lobby); //cast to a LobbyList.Lobby Lobby newLobby = Lobby.FromSteam(client, lobby); if (newLobby.Name != "") { //if the lobby is valid add it to the valid return lobbies Lobbies.Add(newLobby); checkFinished(); } else { //else we need to get the info for the missing lobby client.native.matchmaking.RequestLobbyData(lobby); if (!registeredLobbyDataUpdated) { client.RegisterCallback <SteamNative.LobbyDataUpdate_t>(OnLobbyDataUpdated); registeredLobbyDataUpdated = true; } } } checkFinished(); if (OnLobbiesUpdated != null) { OnLobbiesUpdated(); } }
/// <summary>Updates the lobbies list.</summary> private void UpdateLobbies() { Lobbies.Clear(); Lobbies = new ObservableCollection <LobbyInstance>(ClientManager.Instance.LobbiesInSession.Values); if (Lobbies.Count == 4) { CreateEnabled = "false"; } else { CreateEnabled = "true"; } NotifyOfPropertyChange(() => Lobbies); }
private void ClientDisonnect(Lobby lobby) { try { Logger.Info($"Пользователь {lobby.User.Nickname} отключился от сервера."); OnlineUsers.Remove(lobby.User); Lobbies.Remove(lobby); lobby.Socket.Shutdown(SocketShutdown.Both); lobby.Socket.Close(); lobby.Socket.Dispose(); }catch (Exception e) { lobby.Socket.Dispose(); Logger.Error($"Ошибка при отключении клиента от сервера: \n {e}"); } }
/// <summary> /// Refresh the List of Lobbies. If no filter is passed in, a default one is created that filters based on AppId ("appid"). /// </summary> /// <param name="filter"></param> public void Refresh(Filter filter = null) { //init out values Lobbies.Clear(); requests.Clear(); Finished = false; if (filter == null) { filter = new Filter(); filter.StringFilters.Add("appid", client.AppId.ToString()); filter.DistanceFilter = Filter.Distance.Worldwide; //client.native.matchmaking.RequestLobbyList(OnLobbyList); //return; } client.native.matchmaking.AddRequestLobbyListDistanceFilter((SteamNative.LobbyDistanceFilter)filter.DistanceFilter); if (filter.SlotsAvailable != null) { client.native.matchmaking.AddRequestLobbyListFilterSlotsAvailable((int)filter.SlotsAvailable); } if (filter.MaxResults != null) { client.native.matchmaking.AddRequestLobbyListResultCountFilter((int)filter.MaxResults); } foreach (KeyValuePair <string, string> fil in filter.StringFilters) { client.native.matchmaking.AddRequestLobbyListStringFilter(fil.Key, fil.Value, SteamNative.LobbyComparison.Equal); } foreach (KeyValuePair <string, int> fil in filter.NearFilters) { client.native.matchmaking.AddRequestLobbyListNearValueFilter(fil.Key, fil.Value); } //foreach (KeyValuePair<string, KeyValuePair<Filter.Comparison, int>> fil in filter.NumericalFilters) //{ // client.native.matchmaking.AddRequestLobbyListNumericalFilter(fil.Key, fil.Value.Value, (SteamNative.LobbyComparison)fil.Value.Key); //} // this will never return lobbies that are full (via the actual api) client.native.matchmaking.RequestLobbyList(OnLobbyList); }
private void OnClientDeleteChannel(object sender, ClientEventArgs e) { if (e.clientChannelMsg2 != "Deny") { if (Lobbies.Contains(e.clientChannelMsg)) { lobbies.Remove(e.clientChannelMsg); } if (JoinedChannelsList.Contains(e.clientChannelMsg)) { joinedChannelsList.Remove(e.clientChannelMsg); } MessageBox.Show(e.clientChannelMsg2 + " deleted channel " + e.clientChannelMsg, "Gold Chat: " + User.strName, MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show(e.clientChannelMsg, "Gold Chat: " + User.strName, MessageBoxButton.OK, MessageBoxImage.Stop); } }
void OnLobbyDataUpdated(LobbyDataUpdate_t callback) { if (callback.Success == 1) //1 if success, 0 if failure { //find the lobby that has been updated Lobby lobby = Lobbies.Find(x => x.LobbyID == callback.SteamIDLobby); //if this lobby isn't yet in the list of lobbies, we know that we should add it if (lobby == null) { Lobbies.Add(lobby); checkFinished(); } //otherwise lobby data in general was updated and you should listen to see what changed if (OnLobbiesUpdated != null) { OnLobbiesUpdated(); } } }
public Lobby GetLobby(ISocketMessageChannel channel) { return(Lobbies.Find(channel.Id)); }
public Lobby GetLobbyWithQueue(ISocketMessageChannel channel) { return(Lobbies.Where(x => x.ChannelId == channel.Id).Include(x => x.Queue).FirstOrDefault()); }
public void Add(Lobby lobby) { Lobbies.Add(lobby); }