SA-MP Forums Archive
PHP accessing PAWN - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: PHP accessing PAWN (/showthread.php?tid=411579)

Pages: 1 2


PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

Hello guys.
I have some ideas how to do some stuff but it is better to ask for your opinion about the best methods for doing it.
I want to do something on the web page (eg. press a button to collect a reward) and then the php server will inform the samp server about that change (if the player is online - update his money, if not the update the mysql database).
I found 2 possible solutions on this forum, the sockets plugin by BlueG and the php libraries by Y_Less.
So i wanted to ask you guys what is the better solution for this kind of stuff?

The most important part is if that player is online, how to update his information via php accessing samp. Thank you


Re: PHP accessing PAWN - mineralo - 29.01.2013

you can't to accessing somehow samp but you can make an table in mysql and after in game updating this table every time when a player connect or disconnect, I saw something like this in one server
http://springvalerpg.com/info.php


Re: PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

Read the post, I want to be able to update the user stats if they are changed by the web server (eg. an admin bans a player via admin web panel, or gives a level to a player etc.)


AW: PHP accessing PAWN - Kwashiorkor - 29.01.2013

@mineralo: sure thats possible
@gigi: connect via westies rcon api and use packetSend(). that query can be received under https://sampwiki.blast.hk/wiki/OnRconCommand. you just have to parse cmd[] and execute what you want to. thats it


Re: PHP accessing PAWN - zgintasz - 29.01.2013

If I understood correctly, in OnPlayerConnect add player's id and player's name, in OnPlayerDisconnect remove it. Then, connect using php to mysql and check if the name is in mysql, if yes - player is connected, if not - player isn't connected. For communicating you can use sockets plugin or make another mysql table and with timer in server check if there is a "task" in mysql, after completing "task" remove that field from mysql, for example:
for what player | task
Player_Name | addscore 10

if there is set task, do it and remove that field.
I really don't know how to explain easily, hope you understood .


Re: PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

@Kwashiorkor thanks for that solution too, but I don't think that is too secure?

@zgintasz nice idea for the tasks way, didn't think about that al all! It would be very elegant to do it like that, without the need of extra plugins or libraries, but would it be efficient to access the table whole the time with a timer ?

ps. using mysql plugin r6 (blueg)


Re: PHP accessing PAWN - zgintasz - 29.01.2013

I'm not sure about efficiency, but if mysql plugin supports threaded scripts, you may do that in separate thread. Also, using this method("tasks") would be much easier and simplier than sockets or anything else.


Re: PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

Yes it does support, and I think too that it is a lot easier than the sockets way or anything else.
Will wait for some more replies but I think I will do it this way.


AW: Re: PHP accessing PAWN - Kwashiorkor - 29.01.2013

Quote:
Originally Posted by Gigi-The-Beast
View Post
@Kwashiorkor thanks for that solution too, but I don't think that is too secure?
there are no vulnerabilities to exploit. you have to connect with your rcon password and the server only accepts authorized commands - it's like "/rcon login pw" ingame. by the way it's the only way to sync your php script and the gamemode in real-time


Re: PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

Quote:
Originally Posted by Kwashiorkor
View Post
by the way it's the only way to sync your php script and the gamemode in real-time
Well, not exactly, because the sockets plugin provides callbacks for sending/receiving data between samp server and another server (php), so that plugin too provides real time updates.
But anyway, thank you too for help and providing another way of achieving my goal, I just think that the "tasks" aproach is a lot easier.


Re: PHP accessing PAWN - Niko_boy - 29.01.2013

it will be possible if u are able to send data to samp_srvr.exe which afaik is possible.
u can use OnRconCommand and something php thing to send message to console.


Re: PHP accessing PAWN - Y_Less - 29.01.2013

I'm really not sure what people's obsession with using MySQL for everything is! It is a storage system, not a communication system, and using it as such is REALLY not the best way. Given the option, I'd say go with the sockets plugin - that IS a communication system and will be VASTLY more efficient than using an enterprise class highly resilient database system (which in this case will work against you through the vast overheads involved in safely writing all the data to disk).


Re: PHP accessing PAWN - zgintasz - 29.01.2013

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
I'm really not sure what people's obsession with using MySQL for everything is! It is a storage system, not a communication system, and using it as such is REALLY not the best way. Given the option, I'd say go with the sockets plugin - that IS a communication system and will be VASTLY more efficient than using an enterprise class highly resilient database system (which in this case will work against you through the vast overheads involved in safely writing all the data to disk).
I know, but I don't think it's great idea to load more plugins on server for one simple thing instead of using a little bit tricks. I know, it's not the real solution, but it isn't super huge commercial project, it's just a simple sa-mp server.


Re: PHP accessing PAWN - Y_Less - 29.01.2013

Why, what's the problem with more plugins? They don't have any serious overhead associated with them (except the MySQL one, which requires libmysql).


Re: PHP accessing PAWN - Mauzen - 29.01.2013

Just repeating what already was said, id go either with sockets, or with the rcon api. These are the only two effective ways to do it in realtime.
Querying is an easy and secure way when you got the samp- and webserver on the same machine. No external communication then, and your data is as safe as the rest of your stuff, so there wouldnt be an extra risk.
Sockets would need some additional knowledge, but shouldnt be a problem for anyone with pawn and php skills.


Re: PHP accessing PAWN - zgintasz - 29.01.2013

If he use sockets, he will need more knowledge, I'm not sure if he wants to learn about that. Maybe he just want to make this thing fast and easily.
Anyway, using php, sockets using is easier than using c++, so I don't know which way should he choose...


Re: PHP accessing PAWN - Gigi-The-Beast - 29.01.2013

Well, I don't mind learning more stuff, as at the end I want to develop a full user control panel and allow users to change lot of things via the web but at the same time allow them to be in-game, so if sockets are the most efficient solution, i'll start messing with it


Re: PHP accessing PAWN - AndreT - 29.01.2013

I think that the sockets plugin is the best way to approach webserver to gameserver and vice versa communications. For simple one-way comms, you could also take advantage of the HTTP() function.

When you know how to do some PHP, you can also manage setting up and caching data in the memory using APC for example.


Re: PHP accessing PAWN - Y_Less - 30.01.2013

Actually, you can use HTTP for two-way comms because the web server returns data. That's how y_php works.


Re: PHP accessing PAWN - Gigi-The-Beast - 30.01.2013

Yes but the web server responds only when a HTTP is sent from the samp server to the web server, but there is no way to triger a callback directly when data is sent from the webserver first, and that is exactly what I want.