Browse Source

Add disconnect on close & fix event handler adding

new_protocol
ThePerkinrex 5 years ago
parent
commit
9744856194
No known key found for this signature in database GPG Key ID: FD81DE6D75E20917
  1. 7
      unity/Assets/Scripts/Client.cs
  2. 2
      unity/Assets/Scripts/MainMenuController.cs

7
unity/Assets/Scripts/Client.cs

@ -32,6 +32,10 @@ public class Client : MonoBehaviour {
} }
} }
void OnApplicationQuit() {
CloseConnection();
}
public class NetEventManager { public class NetEventManager {
private Dictionary<string, Action<Common.Name>> returnNameHandlers = new Dictionary<string, Action<Common.Name>>(); private Dictionary<string, Action<Common.Name>> returnNameHandlers = new Dictionary<string, Action<Common.Name>>();
private Dictionary<string, Action<Connection.UserID>> returnConnectHandlers = new Dictionary<string, Action<Connection.UserID>>(); private Dictionary<string, Action<Connection.UserID>> returnConnectHandlers = new Dictionary<string, Action<Connection.UserID>>();
@ -352,8 +356,7 @@ public class Client : MonoBehaviour {
} }
public void Close() { public void Close() {
// connection.disconnect(new Google.Protobuf.WellKnownTypes.Empty(), new Metadata { new Metadata.Entry("client_id", connId) }); conn.SendMessage(new Protocol.ClientServerPacket() {Disconnect = new Empty()});
// channel.ShutdownAsync().Wait();
} }
} }

2
unity/Assets/Scripts/MainMenuController.cs

@ -182,7 +182,6 @@ public class MainMenuController : MonoBehaviour {
if (conn != null) { if (conn != null) {
var lobby = conn.GetLobby(); var lobby = conn.GetLobby();
if (lobby == null) { if (lobby == null) {
conn.CreateLobby(true);
conn.eventManager.AddHandler("ui_create_lobby", (Connection.LobbyCode lobby1) => { conn.eventManager.AddHandler("ui_create_lobby", (Connection.LobbyCode lobby1) => {
Debug.Log("Lobby created"); Debug.Log("Lobby created");
lobby = Base32.ToString(lobby1.Code); lobby = Base32.ToString(lobby1.Code);
@ -193,6 +192,7 @@ public class MainMenuController : MonoBehaviour {
ReloadMenu(); ReloadMenu();
conn.eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnCreateLobby, "ui_create_lobby"); conn.eventManager.RemoveHandler(Protocol.ServerClientPacket.DataOneofCase.ReturnCreateLobby, "ui_create_lobby");
}); });
conn.CreateLobby(true);
} }
} }
} }

Loading…
Cancel
Save