2020-08-05 18:50:28 +02:00
|
|
|
|
using UnityEngine;
|
2020-08-07 20:20:13 +02:00
|
|
|
|
using NeonTea.Quakeball.Networking.Instances;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
using NeonTea.Quakeball.TeaNet.Peers;
|
2020-08-07 23:47:03 +02:00
|
|
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
2020-08-05 18:50:28 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-07 20:20:13 +02:00
|
|
|
|
namespace NeonTea.Quakeball.Networking {
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-02 20:32:30 +02:00
|
|
|
|
public class Net {
|
|
|
|
|
public static Net Singleton = new Net();
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-07 03:46:09 +02:00
|
|
|
|
public NetInstance Instance;
|
2020-08-02 02:50:01 +02:00
|
|
|
|
|
2020-08-08 19:14:34 +02:00
|
|
|
|
public void StartClient(string address, int port, string nick, PeerMessageListener listener) {
|
2020-08-07 03:46:09 +02:00
|
|
|
|
Instance = new Client();
|
2020-08-08 19:14:34 +02:00
|
|
|
|
Instance.Start(address, port, nick, listener);
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 19:14:34 +02:00
|
|
|
|
public void StartServer(string address, int port, string nick, PeerMessageListener listener) {
|
2020-08-07 03:46:09 +02:00
|
|
|
|
Instance = new Server();
|
2020-08-08 19:14:34 +02:00
|
|
|
|
Instance.Start(address, port, nick, listener);
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
2020-08-05 03:21:04 +02:00
|
|
|
|
|
2020-08-07 03:46:09 +02:00
|
|
|
|
public static void Quit() {
|
2020-08-07 04:36:20 +02:00
|
|
|
|
if (Singleton.Instance != null) {
|
|
|
|
|
Singleton.Instance.Stop();
|
|
|
|
|
}
|
2020-08-05 03:21:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RuntimeInitializeOnLoadMethod]
|
|
|
|
|
static void RunOnStart() {
|
|
|
|
|
Application.quitting += Quit;
|
|
|
|
|
}
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|
2020-08-07 23:47:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class ByteBufferExtensions {
|
|
|
|
|
/// <summary>Extension: Reads Vector3</summary>
|
|
|
|
|
public static Vector3 ReadVector3(this ByteBuffer buffer) {
|
|
|
|
|
float x = buffer.ReadFloat();
|
|
|
|
|
float y = buffer.ReadFloat();
|
|
|
|
|
float z = buffer.ReadFloat();
|
|
|
|
|
return new Vector3(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Extension: Writes Vector3</summary>
|
|
|
|
|
public static void Write(this ByteBuffer buffer, Vector3 vector) {
|
|
|
|
|
buffer.Write(vector.x);
|
|
|
|
|
buffer.Write(vector.y);
|
|
|
|
|
buffer.Write(vector.z);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-02 02:50:01 +02:00
|
|
|
|
}
|