Raised This Month: $32 Target: $400
 8% 

Server Information Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KrazyKat
Member
Join Date: Mar 2021
Old 03-15-2022 , 23:54   Server Information Menu
Reply With Quote #1

Hello, is there a plugin that can read and write server information hosted in the same machine (map, players) into/from a file and access it as a menu?
KrazyKat is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-16-2022 , 09:01   Re: Server Information Menu
Reply With Quote #2

Not directly, you would have to send the file through sockets or set up a MySQL server in the machine.

A similar thread was open not too long ago
https://forums.alliedmods.net/showthread.php?t=336849
__________________









Last edited by CrazY.; 03-16-2022 at 09:01.
CrazY. is offline
KrazyKat
Member
Join Date: Mar 2021
Old 03-16-2022 , 19:52   Re: Server Information Menu
Reply With Quote #3

Quote:
Originally Posted by CrazY. View Post
Not directly, you would have to send the file through sockets or set up a MySQL server in the machine.

A similar thread was open not too long ago
https://forums.alliedmods.net/showthread.php?t=336849
Is it possible to make a custom plugin that reads server information locally and updates it regularly? Sockets is crashing on my server, so Curl is the only option.
KrazyKat is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-17-2022 , 11:35   Re: Server Information Menu
Reply With Quote #4

I'm not sure if you can do that with curl, unless you've control over the machine to set up a web server then send http requests in the plugins to store/retrieve data.

You shouldn't be using amxmodx sockets module, it's in blocking mode, which basically means your server will hang up every time you do a request. I used sockets_hz on a few of my projects, check if it works on your server. Threaded sockets seems a good option as well, definitely give it a try.

sockets_hz
linux: https://forums.alliedmods.net/showthread.php?t=60026
windows: https://forums.alliedmods.net/showpo...8&postcount=15

threaded sockets
https://forums.alliedmods.net/showth...t=60026&page=2
latest https://github.com/ShootingKing-AM/T...ckets/releases

Here's a sample plugin made with sockets_hz, tested on a local windows server

server
Code:
#include <amxmodx>
#include <sockets_hz>

new const HOST[] = "127.0.0.1"
const PORT = 4444

new g_server

public plugin_init()
{
	new error
	g_server = socket_listen(HOST, PORT, SOCKET_TCP, error)

	if (g_server <= 0)
	{
		server_print("^t socket_listen() failed: error %d", error)
	}
	else
	{
		server_print("^t server listening on %s:%d", HOST, PORT)

		socket_unblock(g_server)

		set_task(1.0, "Listen", .flags = "b")
	}
}

public plugin_end()
{
	if (g_server > 0)
	{
		socket_close(g_server)
	}
}

public Listen()
{
	new client = socket_accept(g_server)

	if (client <= 0)
	{
		return
	}

	server_print("^t [%.2f] client connected", get_gametime())

	socket_unblock(client)

	set_task(1.0, "RecvData", client, .flags = "b")
}

public RecvData(client)
{
	if (!socket_change(client, 0))
	{
		return
	}

	new buffer[1024]
	new bytes = socket_recv(client, buffer, sizeof buffer)

	switch (bytes)
	{
		case -1:
		{
			// error

			server_print("^t [%.2f] socket_recv() failed", get_gametime())
		}
		case 0:
		{
			// connection closed

			server_print("^t [%.2f] client disconnected", get_gametime())

			socket_close(client)
			remove_task(client)
		}
		default:
		{
			server_print("^t received %d bytes", bytes)
			server_print("^t --------------------------")
			server_print("^t %s", buffer)
			server_print("^t --------------------------")

			copy(buffer, charsmax(buffer), "send this back to the client")
			bytes = socket_send(client, buffer, sizeof buffer)

			server_print("^t sent %d bytes", bytes)
		}
	}
}
client
Code:
#include <amxmodx>
#include <sockets_hz>

new const HOST[] = "127.0.0.1"
const PORT = 4444

public plugin_init()
{
	new error
	new client = socket_open(HOST, PORT, SOCKET_TCP, error)

	if (client <= 0)
	{
		server_print("^t socket_open() failed: error %d", error)
	}
	else
	{
		socket_unblock(client)

		new const data[] = "send this to the server"
		new bytes = socket_send(client, data, sizeof data)

		if (bytes == -1)
		{
			// error

			server_print("^t socket_send() failed")

			socket_close(client)
		}
		else
		{
			set_task(1.0, "RecvResponse", client, .flags = "b")
		}
	}
}

public RecvResponse(client)
{
	if (!socket_change(client, 0))
	{
		return
	}

	new buffer[1024]
	new bytes = socket_recv(client, buffer, sizeof buffer)

	switch (bytes)
	{
		case -1:
		{
			// error

			server_print("^t [%.2f] socket_recv() failed", get_gametime())
		}
		case 0:
		{
			// connection closed

			server_print("^t connection closed", get_gametime())
		}
		default:
		{
			server_print("^t received %d bytes", bytes)
			server_print("^t --------------------------")
			server_print("^t %s", buffer)
			server_print("^t --------------------------")
		}
	}

	socket_close(client)
	remove_task(client)
}
This uses the TCP protocol. UDP would be faster, you probably wouldn't have problems with it as the server and client are both on the same machine, but with the current natives available in the sockets_hz module, it is only possible to recv on a UDP listening socket, you can't send a response unless you run both, the socket server and client on both game servers, but on different ports.

If sockets isn't an option for you, I'm not sure if it's possible to read files outside the server directory through a plugin. I can't think of a simple solution to the problem, you would need an intermediate between the two servers, either a database server with the sqlx module or a http server with the curl module.

If you've access to the machine, you could set up an automated task to copy files from one to the other.
__________________









Last edited by CrazY.; 03-17-2022 at 11:45.
CrazY. is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-17-2022 , 19:11   Re: Server Information Menu
Reply With Quote #5

https://forums.alliedmods.net/showthread.php?t=150519
bigdaddy424 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode