quakeball/Assets/Scripts/Networking/GameProtocol.cs

46 lines
1.5 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));
RegisterPacket(typeof(SpawnPckt));
RegisterPacket(typeof(SelfIdentPckt));
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
2020-08-07 05:24:46 +02:00
RegisterPacket(typeof(PlayerUpdatePckt));
2020-08-07 22:09:31 +02:00
RegisterPacket(typeof(PlayerJumpPckt));
2020-08-07 23:47:03 +02:00
RegisterPacket(typeof(PlayerSyncPacket));
}
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);
}
}
}