You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
1.4 KiB

using Grpc.Core;
// using UnityEngine;
public static class Client
{
private static Connection reference;
public static void Connect(string name)
{
reference = new Connection(name);
}
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)
{
channel = new Channel("127.0.0.1:50052", 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();
}
}
}