BattleBit-Community-Server-API/Program.cs

90 lines
2.5 KiB
C#
Raw Normal View History

2023-07-28 03:24:00 +03:00
using BattleBitAPI;
2023-08-11 12:34:11 +03:00
using BattleBitAPI.Common;
using BattleBitAPI.Server;
2023-08-17 18:39:20 +03:00
using System.Net;
using System.Numerics;
2023-08-11 14:44:54 +03:00
using System.Threading.Channels;
using System.Xml;
2023-03-03 15:15:17 +03:00
class Program
{
static void Main(string[] args)
{
var listener = new ServerListener<MyPlayer, MyGameServer>();
2023-08-17 18:39:20 +03:00
listener.OnGameServerConnecting += OnGameServerConnecting;
listener.OnValidateGameServerToken += OnValidateGameServerToken;
2023-08-11 13:05:13 +03:00
listener.Start(29294);
2023-08-11 14:44:54 +03:00
2023-07-28 03:24:00 +03:00
Thread.Sleep(-1);
2023-03-03 15:15:17 +03:00
}
2023-08-14 12:43:58 +03:00
2023-08-17 18:39:20 +03:00
private static async Task<bool> OnValidateGameServerToken(IPAddress ip, ushort gameport, string sentToken)
{
await Console.Out.WriteLineAsync(ip + ":" + gameport + " sent " + sentToken);
return true;
}
private static async Task<bool> OnGameServerConnecting(IPAddress arg)
{
await Console.Out.WriteLineAsync(arg.ToString() + " connecting");
return true;
}
2023-08-14 12:43:58 +03:00
2023-07-28 03:24:00 +03:00
}
2023-08-11 14:44:54 +03:00
class MyPlayer : Player<MyPlayer>
2023-07-28 03:24:00 +03:00
{
2023-08-17 18:39:20 +03:00
public override async Task OnSpawned()
2023-08-14 17:13:31 +03:00
{
}
2023-08-11 13:05:13 +03:00
}
class MyGameServer : GameServer<MyPlayer>
{
2023-08-14 12:43:58 +03:00
public override async Task OnConnected()
2023-08-11 14:44:54 +03:00
{
2023-08-14 12:43:58 +03:00
ForceStartGame();
2023-08-17 18:39:20 +03:00
ServerSettings.PlayerCollision = true;
}
public override async Task OnDisconnected()
{
await Console.Out.WriteLineAsync("Disconnected: "+ this.TerminationReason);
}
2023-08-14 17:13:31 +03:00
2023-08-17 18:39:20 +03:00
public override async Task OnTick()
{
base.ServerSettings.PlayerCollision = true;
foreach (var item in AllPlayers)
item.Modifications.CanSuicide = true;
2023-08-11 14:44:54 +03:00
}
2023-08-14 16:21:30 +03:00
public override async Task OnPlayerConnected(MyPlayer player)
{
2023-08-14 17:13:31 +03:00
await Console.Out.WriteLineAsync("Connected: " + player);
2023-08-17 18:39:20 +03:00
2023-08-14 16:21:30 +03:00
}
public override async Task OnPlayerSpawned(MyPlayer player)
{
await Console.Out.WriteLineAsync("Spawned: " + player);
}
public override async Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
{
await Console.Out.WriteLineAsync("Downed: " + args.Victim);
}
public override async Task OnPlayerGivenUp(MyPlayer player)
{
await Console.Out.WriteLineAsync("Giveup: " + player);
}
public override async Task OnPlayerDied(MyPlayer player)
{
await Console.Out.WriteLineAsync("Died: " + player);
}
public override async Task OnAPlayerRevivedAnotherPlayer(MyPlayer from, MyPlayer to)
{
2023-08-14 17:13:31 +03:00
await Console.Out.WriteLineAsync(from + " revived " + to);
2023-08-14 16:21:30 +03:00
}
public override async Task OnPlayerDisconnected(MyPlayer player)
2023-08-11 22:48:28 +03:00
{
2023-08-14 16:21:30 +03:00
await Console.Out.WriteLineAsync("Disconnected: " + player);
2023-08-11 22:48:28 +03:00
}
}