quakeball/Assets/Scripts/Networking/GameProtocol.cs

50 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System;
using UnityEngine;
using NeonTea.Quakeball.TeaNet.Peers;
using NeonTea.Quakeball.TeaNet.Packets;
using NeonTea.Quakeball.Networking.Packets;
using NeonTea.Quakeball.Networking.Instances;
namespace NeonTea.Quakeball.Networking {
public class GameProtocol : Protocol {
public override byte Identifier => 0x7A;
public override string Version => "0.0.1";
private NetInstance Instance;
public GameProtocol(NetInstance instance) {
Instance = instance;
RegisterPacket(typeof(HelloPckt));
2020-08-08 02:35:19 +02:00
RegisterPacket(typeof(PingPckt));
RegisterPacket(typeof(SpawnPckt));
RegisterPacket(typeof(SelfIdentPckt));
2020-08-07 05:24:46 +02:00
RegisterPacket(typeof(PlayerUpdatePckt));
2020-08-08 03:21:02 +02:00
RegisterPacket(typeof(PlayerActionPckt));
2020-08-07 23:47:03 +02:00
RegisterPacket(typeof(PlayerSyncPacket));
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
2020-08-08 00:29:29 +02:00
RegisterPacket(typeof(MultipleSyncsPckt));
RegisterPacket(typeof(HitPckt));
2020-08-08 14:37:55 +02:00
RegisterPacket(typeof(DeadPckt));
}
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {
if (conn.IsReady() && !Instance.Connections.Contains(conn.uid)) {
Instance.Connected(conn);
} else if (conn.IsDisconnected()) {
Instance.Disconnected(conn);
}
}
public override void Receive(Connection conn, Packet packet) {
Instance.Handle(conn, packet);
}
public override void Timeout(Connection conn) {
Instance.Disconnected(conn);
}
}
}