Přidán build script, předělaná struktura, funkční spouštění serveru z clienta. Client je schopen fungovat po více her bez restartu. Bugfixy
This commit is contained in:
parent
c942d23a87
commit
1a27dd6fab
22 changed files with 269 additions and 136 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
|
@ -37,9 +38,8 @@ public class Client {
|
|||
public static ClientPlayer Opponent { get; } = new();
|
||||
|
||||
public static ClientPlayer GetPlayer(int pid) => Player.state.pid == pid ? Player : Opponent;
|
||||
|
||||
public static void Connect(string endPoint, int port) {
|
||||
State = ConnectionState.CONNECTING;
|
||||
|
||||
public static void Init() {
|
||||
writer = new NetDataWriter();
|
||||
processor = new NetPacketProcessor();
|
||||
|
||||
|
|
@ -57,9 +57,6 @@ public class Client {
|
|||
client = new NetManager(listener){
|
||||
AutoRecycle = true
|
||||
};
|
||||
|
||||
client.Start();
|
||||
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
||||
|
||||
listener.NetworkReceiveEvent += (peer, reader, channel, method) => {
|
||||
OnNetworkReceive(peer, reader, method);
|
||||
|
|
@ -71,6 +68,13 @@ public class Client {
|
|||
State = ConnectionState.CONNECTED;
|
||||
SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered);
|
||||
};
|
||||
}
|
||||
|
||||
public static void Connect(string endPoint, int port) {
|
||||
State = ConnectionState.CONNECTING;
|
||||
|
||||
client.Start();
|
||||
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
||||
|
||||
new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work
|
||||
}
|
||||
|
|
@ -108,9 +112,18 @@ public class Client {
|
|||
public static void OnPlayerUpdate(UpdatePlayerPacket packet) { // TODO: move this to a separate class
|
||||
EventProcessor.Evaluate(packet.events);
|
||||
//Player.state = Player.state.pid == 0 ? packet.stateP1 : packet.stateP2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void Disconnect() {
|
||||
if (client == null || client.ConnectedPeersCount == 0) return;
|
||||
client.DisconnectAll();
|
||||
client.Stop();
|
||||
State = ConnectionState.IDLE;
|
||||
}
|
||||
|
||||
public static void StartServer() {
|
||||
Process.Start("FNAF_Server");
|
||||
// new Thread(() => Server.Start(9012)).Start();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue