quakeball/Assets/Scripts/Net/TestProtocol.cs

40 lines
1.4 KiB
C#
Raw Normal View History

2020-08-05 03:21:04 +02:00
using System.Collections.Generic;
using System;
using UnityEngine;
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;
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}");
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) {
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");
}
}
}