Chat message will wait for a callback.
This commit is contained in:
parent
ec935486de
commit
d080cf110c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,6 +11,7 @@
|
|||
SendPlayerStats = 11,
|
||||
SpawnPlayer = 12,
|
||||
SetNewRoomSettings = 13,
|
||||
RespondPlayerMessage = 14,
|
||||
|
||||
PlayerConnected = 50,
|
||||
PlayerDisconnected = 51,
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace BattleBitAPI.Server
|
|||
// ---- Public Variables ----
|
||||
public TcpClient Socket { get; private set; }
|
||||
|
||||
public ulong ServerHash { get; private set; }
|
||||
/// <summary>
|
||||
/// Is game server connected to our server?
|
||||
/// </summary>
|
||||
public ulong ServerHash { get; private set; }
|
||||
public bool IsConnected { get; private set; }
|
||||
public IPAddress GameIP { get; private set; }
|
||||
public int GamePort { get; private set; }
|
||||
|
@ -54,7 +54,7 @@ namespace BattleBitAPI.Server
|
|||
private mInternalResources mInternal;
|
||||
private StringBuilder mBuilder;
|
||||
|
||||
// ---- Constrction ----
|
||||
// ---- Construction ----
|
||||
public GameServer(TcpClient socket, mInternalResources resources, Func<GameServer, mInternalResources, Common.Serialization.Stream, Task> func, IPAddress iP, int port, bool isPasswordProtected, string serverName, string gamemode, string map, MapSize mapSize, MapDayNight dayNight, int currentPlayers, int inQueuePlayers, int maxPlayers, string loadingScreenText, string serverRulesText)
|
||||
{
|
||||
this.IsConnected = true;
|
||||
|
|
|
@ -92,7 +92,10 @@ namespace BattleBitAPI.Server
|
|||
/// ChatChannel: The channel the message was sent <br/>
|
||||
/// string - Message: The message<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, ChatChannel, string, Task> OnPlayerTypedMessage { get; set; }
|
||||
/// <value>
|
||||
/// Returns: True if you let the message broadcasted, false if you don't it to be broadcasted.
|
||||
/// </value>
|
||||
public Func<TPlayer, ChatChannel, string, Task<bool>> OnPlayerTypedMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player kills another player.
|
||||
|
@ -794,8 +797,9 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
case NetworkCommuncation.OnPlayerTypedMessage:
|
||||
{
|
||||
if (stream.CanRead(8 + 1 + 2))
|
||||
if (stream.CanRead(2 + 8 + 1 + 2))
|
||||
{
|
||||
ushort messageID = stream.ReadUInt16();
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var player))
|
||||
|
@ -803,8 +807,18 @@ namespace BattleBitAPI.Server
|
|||
ChatChannel chat = (ChatChannel)stream.ReadInt8();
|
||||
if (stream.TryReadString(out var msg))
|
||||
{
|
||||
bool pass = true;
|
||||
if (OnPlayerTypedMessage != null)
|
||||
await OnPlayerTypedMessage.Invoke((TPlayer)player, chat, msg);
|
||||
pass = await OnPlayerTypedMessage.Invoke((TPlayer)player, chat, msg);
|
||||
|
||||
//Respond back.
|
||||
using (var response = Common.Serialization.Stream.Get())
|
||||
{
|
||||
response.Write((byte)NetworkCommuncation.RespondPlayerMessage);
|
||||
response.Write(messageID);
|
||||
response.Write(pass);
|
||||
server.WriteToSocket(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
Program.cs
35
Program.cs
|
@ -1,7 +1,9 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using BattleBitAPI.Storage;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Numerics;
|
||||
|
||||
class Program
|
||||
|
@ -9,21 +11,32 @@ class Program
|
|||
static void Main(string[] args)
|
||||
{
|
||||
var listener = new ServerListener<MyPlayer>();
|
||||
listener.OnGameServerTick += OnGameServerTick;
|
||||
listener.Start(29294);//Port
|
||||
listener.Start(29294);
|
||||
|
||||
listener.OnPlayerTypedMessage += OnPlayerTypedMessage;
|
||||
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
||||
private static async Task OnGameServerTick(GameServer server)
|
||||
private static async Task<bool> OnPlayerTypedMessage(MyPlayer player, ChatChannel ch, string msg)
|
||||
{
|
||||
//server.Settings.SpectatorEnabled = !server.Settings.SpectatorEnabled;
|
||||
//server.MapRotation.AddToRotation("DustyDew");
|
||||
//server.MapRotation.AddToRotation("District");
|
||||
//server.GamemodeRotation.AddToRotation("CONQ");
|
||||
//server.ForceEndGame();
|
||||
if (msg == "nword")
|
||||
{
|
||||
player.NumberOfNWord++;
|
||||
if (player.NumberOfNWord > 4)
|
||||
{
|
||||
player.Kick("N word is not accepted!");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Message("Do not type nword, this is your " + player.NumberOfNWord + "th warning");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class MyPlayer : Player
|
||||
{
|
||||
|
||||
}
|
||||
public int NumberOfNWord;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue