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(); } } }
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); } }
/// <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); }
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(); } }
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 void Add(Lobby lobby) { Lobbies.Add(lobby); }