Create Mods.Common
Create a small base for Mods.Common and update solution and makefile to use it
This commit is contained in:
37
OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs
Normal file
37
OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Server;
|
||||
using S = OpenRA.Server.Server;
|
||||
|
||||
namespace OpenRA.Mods.Common.Server
|
||||
{
|
||||
public class PlayerPinger : ServerTrait, ITick
|
||||
{
|
||||
int PingInterval = 5000; // Ping every 5 seconds
|
||||
|
||||
// TickTimeout is in microseconds
|
||||
public int TickTimeout { get { return PingInterval * 100; } }
|
||||
|
||||
int lastPing = 0;
|
||||
bool isInitialPing = true;
|
||||
public void Tick(S server)
|
||||
{
|
||||
if ((Game.RunTime - lastPing > PingInterval) || isInitialPing)
|
||||
{
|
||||
isInitialPing = false;
|
||||
lastPing = Game.RunTime;
|
||||
foreach (var p in server.Conns)
|
||||
server.SendOrderTo(p, "Ping", Game.RunTime.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user