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 18:50:28 +02:00
|
|
|
public override string Version => "0.0.2";
|
|
|
|
|
|
|
|
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 18:50:28 +02:00
|
|
|
if (newStatus == ConnectionStatus.Ready && !Net.Singleton.Connections.Contains(conn)) {
|
|
|
|
Net.Singleton.Connections.Add(conn);
|
|
|
|
} else if (newStatus == ConnectionStatus.Closed) {
|
|
|
|
Net.Singleton.Peer.MessageListener.Message($"Conncection closed: {conn.ClosingReason}");
|
|
|
|
}
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|