GithubHelp home page GithubHelp logo

bytexdigital / bytexdigital.battleye.rcon Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 8.0 126 KB

A simple to use RCON library for BattlEye

License: Apache License 2.0

C# 100.00%
battleye battleye-rcon dotnet library net-standard rcon

bytexdigital.battleye.rcon's Introduction

BytexDigital.BattlEye.Rcon

This library provides an easy way of communicating with a BattlEye RCON server.

Installation

nuget package

Nuget (with prereleases)

Usage

Creating an RconClient

RconClient networkClient = new RconClient("127.0.0.1", 2310, "testPassword");

Connecting

Notice: By default, the RconClient will attempt reconnecting after a initial Connect() call or when the client is disconnected. You can adjust this behaviour by setting ReconnectInterval and ReconnectOnFailure.

// Connect
bool initialConnectSuccessful = networkClient.Connect();

// Optionally make sure we are connected
networkClient.WaitUntilConnected();

Sending a request that does not expect a response

networkClient.Send(new SendMessageCommand("This is a global message"));

Sending a request that returns something

bool requestSuccess = networkClient.Fetch(
	command: new GetPlayersRequest(),
	timeout: 5000,
	result: out List<Player> onlinePlayers);

Example: Request players and send everyone with an odd ID a personal message

bool requestSuccess = networkClient.Fetch(
	command: new GetPlayersRequest(),
	timeout: 5000,
	result: out List<Player> onlinePlayers);

foreach (var player in onlinePlayers.Where(x => x.Id % 2 != 0)) {
	networkClient.Send(new SendMessageCommand(player.Id, "You're a special person"));
}

Events

A RconClient offers the ability to hook up eventhandlers for specific events. The currently implemented events are when a player connects (PlayerConnected), disconnects (PlayerDisconnected), when a message not bound to a request is received ( for example a chat message) (MessageReceived) and when a player is removed due to a kick or ban (PlayerRemoved).

License

Copyright 2019 Bytex Digital UG (haftungsbeschränkt)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

bytexdigital.battleye.rcon's People

Contributors

lyl-freeman avatar ryantt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bytexdigital.battleye.rcon's Issues

disconnects every 12m 56s

Hi,

I'm using your library (version 1.0.3-beta.4) in a .NET 6.0 project to control a DayZ server.
The client gets disconnected every 12 minutes and 56 seconds.

2021-12-13 16:13:55.532 INFO: Connected
2021-12-13 16:13:55.532 INFO: Server message: RCon admin #0 (127.0.0.1:57095) logged in
2021-12-13 16:26:51.629 INFO: Disconnected
2021-12-13 16:26:51.629 INFO: Connected
2021-12-13 16:26:51.630 INFO: Server message: RCon admin #1 (127.0.0.1:43417) logged in
2021-12-13 16:39:47.724 INFO: Disconnected
2021-12-13 16:39:47.725 INFO: Connected
2021-12-13 16:39:47.725 INFO: Server message: RCon admin #0 (127.0.0.1:38093) logged in
2021-12-13 16:52:43.832 INFO: Disconnected
2021-12-13 16:52:43.833 INFO: Connected
2021-12-13 16:52:43.833 INFO: Server message: RCon admin #1 (127.0.0.1:53917) logged in
2021-12-13 17:05:39.923 INFO: Disconnected
2021-12-13 17:05:39.923 INFO: Connected
2021-12-13 17:05:39.923 INFO: Server message: RCon admin #0 (127.0.0.1:49140) logged in
2021-12-13 17:18:36.013 INFO: Disconnected
2021-12-13 17:18:36.013 INFO: Connected
2021-12-13 17:18:36.014 INFO: Server message: RCon admin #1 (127.0.0.1:35456) logged in

Any idea what could be causing this?

Cheers
Phil

SocketException

Yeah it seems like there is an issue in the BytexDigital.BattlEye.Rcon.NetworkConnection class.

Here is the full error:

Anwendung: EvoRCON.exe
Frameworkversion: v4.0.30319
Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet.
Ausnahmeinformationen: System.Net.Sockets.SocketException
bei System.Net.Sockets.Socket.DoBeginReceiveFrom(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags, System.Net.EndPoint, System.Net.SocketAddress, System.Net.Sockets.OverlappedAsyncResult)
bei System.Net.Sockets.Socket.BeginReceiveFrom(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags, System.Net.EndPoint ByRef, System.AsyncCallback, System.Object)
bei System.Net.Sockets.UdpClient.BeginReceive(System.AsyncCallback, System.Object)
bei System.Threading.Tasks.TaskFactory1[[System.Net.Sockets.UdpReceiveResult, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FromAsyncImpl(System.Func3<System.AsyncCallback,System.Object,System.IAsyncResult>, System.Func2<System.IAsyncResult,System.Net.Sockets.UdpReceiveResult>, System.Action1<System.IAsyncResult>, System.Object, System.Threading.Tasks.TaskCreationOptions)
bei System.Net.Sockets.UdpClient.ReceiveAsync()
bei BytexDigital.BattlEye.Rcon.NetworkConnection+d__21.MoveNext()
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()

GetMissionsRequest doese not realized

GetMissionsRequest doese not realized

RconClient networkClient = new RconClient("192.168.1.1", 2344, "pswd");

            bool requestSuccess = networkClient.Fetch(
                command: new GetMissionsRequest(),
                timeout: 5000,
                result: out string missions);

InvalidOperationException

[DayZ] one instance connecting multiple times?

Hey,

opening the connection before the gameserver is ready (sometimes) seems to lead to multiple connections.

The code I'm using (excerpt):

try
{
	RconClient beClient = new(server.Ip, server.Port, server.Password);
	beClient.ReconnectInterval = 5000;
	beClient.Connected += (sender, args) => NetworkClient_Connected(sender, args);
	beClient.Disconnected += (sender, args) => NetworkClient_Disconnected(sender, args);
	beClient.MessageReceived += (sender, args) => NetworkClient_MessageReceived(sender, args);
	beClient.PlayerConnected += (sender, args) => NetworkClient_PlayerConnected(sender, args);
	beClient.PlayerDisconnected += (sender, args) => NetworkClient_PlayerDisconnected(sender, args);
	beClient.PlayerRemoved += (sender, args) => NetworkClient_PlayerRemoved(sender, args);

	bool initialConnectSuccessful = beClient.Connect();

	bool terminate = false;
	while (!terminate)
	{
		beClient.WaitUntilConnected();

		// [...]
		// do some stuff...
		// [...]

		Thread.Sleep(restartDelay * 1000);

		logger.Info("shutdown server...");
		beClient.Send(new ShutdownCommand());

		// the gameserver will be restarted by another program...

		Thread.Sleep(30000);
	}
}
catch (Exception ex)
{
	logger.Error(ex.ToString());
}

program output:

2022-11-04 08:53:03.266 INFO: Connected
2022-11-04 08:53:03.468 INFO: Server message: RCon admin #0 (127.0.0.1:57631) logged in
2022-11-04 08:53:03.468 INFO: Server message: RCon admin #0 (127.0.0.1:57631) logged in
2022-11-04 08:53:03.890 INFO: Server message: RCon admin #1 (127.0.0.1:37491) logged in
2022-11-04 08:53:03.890 INFO: Server message: RCon admin #1 (127.0.0.1:37491) logged in

gameserver output:

 8:53:03 Mission read.
 8:53:03 Connected to Steam
 8:53:03 Steam policy response
 8:53:03 BattlEye Server: RCon admin #0 (127.0.0.1:57631) logged in
 8:53:03 BattlEye Server: RCon admin #1 (127.0.0.1:37491) logged in

Both connections seem to be "alive", because both receive the NetworkClient_MessageReceived event (duplicates in program output).
However, one of those connections seems to "die", because after X seconds (can't tell exactly) there are no more duplicate log messages, just one per event (as expected).

Any ideas?

Thanks

Help a noob

Hey, anyone interested in helping out a noob here please?

I've got a little launcher setup in VS c# and im trying to connect to a Dayz server just to show how many players are online.
That's all I'm trying to do and i just cant get it to work hehe.. anyone able to share some coding which i can use to show online players in a textbox or label or something please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.