Comments (2)
Edit 1: This was working then suddenly just stopped working
Found a temporary fix. Not a huge fan of it but it works!
It works by the Host checking how many players there are not including themselves, if there's more than 0, we force them to disconnect.
Once they have all disconnected we then close the server.
Won't close the issue just yet in case there is a better solution
So when the host clicks leave the Steam Lobby Manager script does:
public void HandleLeave() {
Player[] players = FindObjectsOfType<Player>();
if (players.CheckIfOnHost())
{
Debug.LogError("On host disconnecting people");
NetworkManager.Singleton.ForceRemoveClients();
}
else
{
NetworkManager.Singleton.LeaveGame();
LeaveLobby();
}
}
Network Manager then removes all the clients:
public void ForceRemoveClients()
{
playersToDisconnect = Player.List.Count - 1;
bHostDisconnect = true;
if (playersToDisconnect > 0)
{
foreach (Player player in Player.List.Values)
{
if (player.bIsHostPlayer)
{
continue;
}
GameServer.DisconnectClient(player.Id);
}
}
else
{
LeaveGame();
LobbyManager.Singleton.LeaveLobby();
}
}
Network Manager also has an event bound to it's Server.ClientDisconnected
which is PlayerLeftServer
Void Start()
{
//Other bits but main important bit for this "fix" is:
SteamServer steamServer = new SteamServer();
GameServer = new Server(steamServer);
GameServer.ClientConnected += PlayerJoined;
GameServer.ClientDisconnected += PlayerLeftServer;
}
And then finally PlayerLeftServer:
private void PlayerLeftServer(object sender, ServerDisconnectedEventArgs e)
{
if(bHostDisconnect)
{
Debug.LogError("Testing Player Left");
playersToDisconnect--;
if (playersToDisconnect <= 0)
{
LeaveGame();
LobbyManager.Singleton.LeaveLobby();
}
}
}
from steamtransport.
Fixed: Stopping Server first seems to have solved my issue!
from steamtransport.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from steamtransport.