43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEngine;
|
|
using NeonTea.Quakeball.TeaNet.Peers;
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
|
using NeonTea.Quakeball.Net.Packets;
|
|
|
|
namespace NeonTea.Quakeball.Net {
|
|
|
|
public class TestProtocol : Protocol {
|
|
public override byte Identifier => 0x7A;
|
|
|
|
public override string Version => "0.0.1";
|
|
|
|
public TestProtocol() {
|
|
RegisterPacket(typeof(HelloPckt));
|
|
}
|
|
|
|
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {
|
|
Peer.MessageListener.Message($"Connection Status Changed into {newStatus.ToString()} for {conn.Endpoint}");
|
|
if (conn.IsReady() && !Net.Singleton.Connections.Contains(conn.uid)) {
|
|
Net.Singleton.Connections.Add(conn.uid);
|
|
} else if (newStatus == ConnectionStatus.Closed) {
|
|
Net.Singleton.Peer.MessageListener.Message($"Conncection closed: {conn.ClosingReason}");
|
|
}
|
|
if (conn.IsDisconnected()) {
|
|
Net.Singleton.Connections.Remove(conn.uid);
|
|
}
|
|
}
|
|
|
|
public override void Receive(Connection conn, Packet packet) {
|
|
if (packet is HelloPckt) {
|
|
HelloPckt Hello = (HelloPckt)packet;
|
|
Peer.MessageListener.Message($"Received HelloPckt: {Hello.Text}");
|
|
}
|
|
}
|
|
|
|
public override void Timeout(Connection conn) {
|
|
Peer.MessageListener.Message($"Closed {conn.Endpoint} for Timeout");
|
|
}
|
|
}
|
|
}
|