[Include] Easy Server Data - Server Information at your fingertips
#1

This basically just gets some very simple server(but nevertheless) useful data such as the IP address, port, maxplayers, etc. There are a few self-explanatory functions.

===============================
GetServerIP() - Gets the servers IP address. This will not work in OnFilterScriptInit(it will work how-ever in a delayed timer placed in said callback).
GetServerPort() - Returns the servers port as an integer value.
GetServerMaxPlayers() - Returns the maximum amount of players as defined in the server.cfg file.
GetServerMaxNPC() - Returns the maximum amount of NPC's as defined in the server.cfg file.
GetConnectedPlayers(lincludenpc=false) - Returns the amount of connected players. If includenpc is true, NPC's will be included so be careful. If left blank, NPC's will be excluded from the player-count.
===============================

That's basically it so here's the download!
- View in Browser -
- Direct download -

Example filterscript:
pawn Code:
#include <a_samp>
#include <serverdata>

public OnFilterScriptInit()
{
    new port = GetServerPort();
    printf("Port: %d", port);
    printf("Max Players: %d Max NPCs: %d", GetServerMaxPlayers(), GetServerMaxNPC());
    SetTimer("DisplayIP", 5000, false);
    return 1;
}

forward DisplayIP();
public DisplayIP()
{
    new IPAddress[32];
    format(IPAddress, sizeof(IPAddress), "%s", GetServerIP());
    printf("The IP address is: %s", IPAddress);
    return true;
}
If you have any questions feel free to ask.
Reply
#2

I have a question: where could you use this? I can't think of a situation for that :/
Reply
#3

Quote:
Originally Posted by dusk
View Post
I have a question: where could you use this? I can't think of a situation for that :/
I Will answer you'r question, You can use this for your mod protection set the mod on IP Protection you can check if the ip + port equal to IP you set up.

and thx good include look nice!
Reply
#4

Nice work, Abagail. Could come in handy.
Reply
#5

This is one of the shittiest scripts I have ever seen.
Reply
#6

Umm...What if your website eventually goes down and the person using this include doesn't know anything about scripting? That would be a real mess.
Reply
#7

All the webpage does is echo the client's IP. How-ever, I will include the page I used. As far as I know, my site hasn't gone down since I first got it.

Here;
Code:
<?php
	function getClientIP() {

		if (isset($_SERVER)) {

			if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
				return $_SERVER["HTTP_X_FORWARDED_FOR"];

			if (isset($_SERVER["HTTP_CLIENT_IP"]))
				return $_SERVER["HTTP_CLIENT_IP"];

			return $_SERVER["REMOTE_ADDR"];
		}

		if (getenv('HTTP_X_FORWARDED_FOR'))
			return getenv('HTTP_X_FORWARDED_FOR');

		if (getenv('HTTP_CLIENT_IP'))
			return getenv('HTTP_CLIENT_IP');

		return getenv('REMOTE_ADDR');
	}
	echo(getClientIp());
?>
And @Turn, at first I thought you were just new and didn't understand anything but know I see that your just being rude, and unhelpful. Let me get some of your recent posts:

Quote:
Originally Posted by Turn
View Post
When are gonna realize that your server is shitty and so is your videos?
Post them on your forum, clearly nobody wants to see them here.
Quote:
Originally Posted by Turn
View Post
"Who cares if the gun disappear"

Are you stupid? the whole point of Mionee's script is for the gun not to dissapear as for the OnPlayerUpdate, it is bad coding not just inaccurate.


But then again, this is a good way of doing it aswell.
If your going to talk shit about my script, atleast point out it's faults; what makes it shitty. I really hope that you get some manners, and decide to come back here with some respect for yourself. Your talking like you know everything, and are better than everyone else - I really don't appreciate your attitude.
Reply
#8

This simple include could be a lot better :

1) format function is useless to copy a string, use strcpy instead.

2) If you're using YSI library for using y_hooks, why don't you use y_iterate too since there's a player loop?

3) Why a function named "GetServerMaxPlayers" when there's already GetMaxPlayers?

4) Server port doesn't change while running, so you can firstly store it on a variable and then keep on returning it when the function is used.

5) "GetServerMaxNPC" - Similar to the above statements.
Reply
#9

@ # 2 - I try to keep the amount of includes needed to a minimum, and keep it simple / straight-forward.

In regards to your next point; things like YSF can change the amount of max players; and therefore GetMaxPlayers won't return the value from the server.cfg file, - thats what this function does. And using format I thought would just be easier since I am formatting a string. Maybe I'll try using strcpy next time.

NOTE: If you wish to host the GetIP page on your own host; just copy the code, and make a PHP page with said code. Then change the link in the include, and you're good to go.
Reply
#10

Quote:
Originally Posted by Abagail
Посмотреть сообщение
And @Turn, at first I thought you were just new and didn't understand anything but know I see that your just being rude, and unhelpful. Let me get some of your recent posts:

Quote:
Originally Posted by Turn
Посмотреть сообщение
When are gonna realize that your server is shitty and so is your videos?
Post them on your forum, clearly nobody wants to see them here.
<- I got 3 reps on that one.

Quote:
Originally Posted by Turn
Посмотреть сообщение
"Who cares if the gun disappear"

Are you stupid? the whole point of Mionee's script is for the gun not to dissapear as for the OnPlayerUpdate, it is bad coding not just inaccurate.


But then again, this is a good way of doing it aswell.
<- I got 2 reps on this one.

If your going to talk shit about my script, atleast point out it's faults; what makes it shitty. I really hope that you get some manners, and decide to come back here with some respect for yourself. Your talking like you know everything, and are better than everyone else - I really don't appreciate your attitude.
ROFL

okay well first of all

You made functions out of functions? what the fuck is that about? GetServerMaxPlayers && GetConnectedPlayers && GetServerMaxNPC equals GetMaxPlayers with a little bit of touch to it.

lol you stole GetServerIP off of https://sampforum.blast.hk/showthread.php?tid=285360.

and finally, your site will shutdown sooner or later and your include won't work anymore so what then?

now lets peek at your threads shall we

https://sampforum.blast.hk/showthread.php?tid=540880 another shitty include how can this be useful when there is already functions to detect if a player knifes another player? OnPlayerTakeDamage & OnPlayerGiveDamage.

https://sampforum.blast.hk/showthread.php?tid=543766 another shitty include. OnPlayerWeaponShot detects that.

https://sampforum.blast.hk/showthread.php?tid=485479 very shitty include easily SetVehiclePos.

lolll
Reply
#11

Ok, and I didn't steal GetServerIP. There's really only one way to do it with PAWN, and if you had any sense at all you'd know that. I really don't care if my script looks like someone else's; I know that I wrote it and didn't copy it - so thats good enough for me, I am not going to let someone like you tell me that I haven't written something.

I haven't even seen that script; you're just trying to feel special because you get no attention and probably never will. I could go on, and on about how rude, and how mean of a person you are but clearly I have better things to do. And I have already stated; that the webpage simply gets the clients IP address. I don't write includes to be long; I write them for a purpose; to do something.

Now; good day sir; I have things to do that don't involve arguing with kids.
Reply
#12

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Ok, and I didn't steal GetServerIP. There's really only one way to do it with PAWN, and if you had any sense at all you'd know that. I really don't care if my script looks like someone else's; I know that I wrote it and didn't copy it - so thats good enough for me, I am not going to let someone like you tell me that I haven't written something.

I haven't even seen that script; you're just trying to feel special because you get no attention and probably never will. I could go on, and on about how rude, and how mean of a person you are but clearly I have better things to do. And I have already stated; that the webpage simply gets the clients IP address. I don't write includes to be long; I write them for a purpose; to do something.

Now; good day sir; I have things to do that don't involve arguing with kids.
this made my day
Reply
#13

One thing: Why use format AND printf in the example?
pawn Код:
forward DisplayIP(); public DisplayIP()
{
    return printf("The IP address is: %s", GetServerIP());
}
Same exact outcome, 4 lines, easily shrinkable to one line also.
Reply
#14

I generally don't think about this kind-of stuff when scripting; I really don't care how it looks as long as I can read it and it isn't too ugly. And since it's just an example; theres no reason to edit it out. Thank you though! Appreciate the positive feedback.

Updated; When GetServerIP is used in something like OnFilterScriptInit it will simply return -1 instead of just returning a blank string.
Reply
#15

Quote:
Originally Posted by Abagail
View Post
@ # 2 - I try to keep the amount of includes needed to a minimum, and keep it simple / straight-forward.

In regards to your next point; things like YSF can change the amount of max players; and therefore GetMaxPlayers won't return the value from the server.cfg file, - thats what this function does. And using format I thought would just be easier since I am formatting a string. Maybe I'll try using strcpy next time.

NOTE: If you wish to host the GetIP page on your own host; just copy the code, and make a PHP page with said code. Then change the link in the include, and you're good to go.
y_hooks itself uses other internal includes of YSI, so you really can't reduce the number of includes required when you're using YSI since it's includes uses internal includes.

YSF changes max player value inside it's memory, I don't think changing maxplayers value on server.cfg while the process is running could change anything. If GetMaxPlayers doesn't return the value after being changed through YSF, then your function isn't useless.
Reply
#16

Updated:
- Added GetServerLaunchTime. For this to work, this must be incorporated into the gamemode script. It will return the timestamp of when the server started.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)