using Grpc.Core; // using UnityEngine; public static class Client { private static Connection reference; public static void Connect(string name, string address="127.0.0.1:50052") { reference = new Connection(name, address); } public static ref Connection GetConnection() { return ref reference; } public static void CloseConnection() { if (reference != null) { reference.Close(); reference = null; } } public class Connection // : MonoBehaviour { private Game.Connection.ConnectionClient connection; private Channel channel; private string connId; private uint? lobby = null; public Connection(string user, string address) { channel = new Channel(address, ChannelCredentials.Insecure); connection = new Game.Connection.ConnectionClient(channel); connId = connection.connect(new Game.Username { Name = user }).Id; } public void JoinLobby(string code) { lobby = Base32.FromString(code); connection.joinLobbyWithCode(new Game.LobbyCode { Code = (uint)lobby }, new Metadata { new Metadata.Entry("client_id", connId) }); } public string CreateLobby() { lobby = connection.joinLobbyWithoutCode(new Game.Null(), new Metadata { new Metadata.Entry("client_id", connId) }).Code; return Base32.ToString((uint)lobby); } public string GetLobby() { if (lobby != null) { return Base32.ToString((uint)lobby); } else { return null; } } public void Close() { channel.ShutdownAsync().Wait(); } } }