2020-08-07 03:46:09 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using NeonTea.Quakeball.TeaNet.Peers;
|
|
|
|
using NeonTea.Quakeball.TeaNet.Packets;
|
2020-08-07 20:20:13 +02:00
|
|
|
using NeonTea.Quakeball.Networking.Packets;
|
|
|
|
using NeonTea.Quakeball.Networking.Instances;
|
2020-08-07 03:46:09 +02:00
|
|
|
|
2020-08-07 20:20:13 +02:00
|
|
|
namespace NeonTea.Quakeball.Networking {
|
2020-08-07 03:46:09 +02:00
|
|
|
|
|
|
|
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));
|
2020-08-07 03:46:09 +02:00
|
|
|
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));
|
2020-08-08 01:10:20 +02:00
|
|
|
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
|
2020-08-08 00:29:29 +02:00
|
|
|
RegisterPacket(typeof(MultipleSyncsPckt));
|
2020-08-08 07:19:46 +02:00
|
|
|
RegisterPacket(typeof(HitPckt));
|
2020-08-07 03:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|