2020-08-05 03:21:04 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
2020-08-05 18:50:28 +02:00
|
|
|
using NeonTea.Quakeball.TeaNet.Peers;
|
|
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
2020-08-05 03:21:04 +02:00
|
|
|
using NeonTea.Quakeball.Net.Packets;
|
|
|
|
|
|
|
|
namespace NeonTea.Quakeball.Net {
|
|
|
|
|
|
|
|
public class TestProtocol : Protocol {
|
|
|
|
public override byte Identifier => 0x7A;
|
|
|
|
|
2020-08-05 19:39:52 +02:00
|
|
|
public override string Version => "0.0.1";
|
2020-08-05 18:50:28 +02:00
|
|
|
|
|
|
|
public TestProtocol() {
|
|
|
|
RegisterPacket(typeof(HelloPckt));
|
|
|
|
}
|
2020-08-05 03:21:04 +02:00
|
|
|
|
|
|
|
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {
|
|
|
|
Peer.MessageListener.Message($"Connection Status Changed into {newStatus.ToString()} for {conn.Endpoint}");
|
2020-08-05 19:39:52 +02:00
|
|
|
if (conn.IsReady() && !Net.Singleton.Connections.Contains(conn.uid)) {
|
|
|
|
Net.Singleton.Connections.Add(conn.uid);
|
2020-08-05 18:50:28 +02:00
|
|
|
} else if (newStatus == ConnectionStatus.Closed) {
|
|
|
|
Net.Singleton.Peer.MessageListener.Message($"Conncection closed: {conn.ClosingReason}");
|
|
|
|
}
|
2020-08-05 19:39:52 +02:00
|
|
|
if (conn.IsDisconnected()) {
|
|
|
|
Net.Singleton.Connections.Remove(conn.uid);
|
|
|
|
}
|
2020-08-05 03:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Receive(Connection conn, Packet packet) {
|
2020-08-05 18:50:28 +02:00
|
|
|
if (packet is HelloPckt) {
|
|
|
|
HelloPckt Hello = (HelloPckt)packet;
|
|
|
|
Peer.MessageListener.Message($"Received HelloPckt: {Hello.Text}");
|
|
|
|
}
|
2020-08-05 03:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Timeout(Connection conn) {
|
|
|
|
Peer.MessageListener.Message($"Closed {conn.Endpoint} for Timeout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|