-
Notifications
You must be signed in to change notification settings - Fork 0
Python Edition
PIP must be installed in your project
pip Command:
pip install https://github.com/Creadores-Program/ServerWebGamePost/releases/download/1.2.1/ServerWebGamePost-1.2.0.Python.Edition.tar.gz
And:
pip install request
# or require in your script
in your File.py:
import ServerWebGamePost
Caution
THE SERVER MUST BE OPENED IN A THREAD SEPARATE FROM THE MAIN ONE SINCE THE MODULE USED ENTERS AN INFINITE LOOP TO RECEIVE REQUESTS
First you need to extend the ServerWebGamePost.Server.ProcessDatapackServer class
And to process the datapackets that the client sends you must implement processDatapack function Something like that:
class MyProcessorDatapacks(ServerWebGamePost.Server.ProcessDatapackServer):
def processDatapack(self, datapack): # datapack = json object
#code...
Simply in the ServerWebGamePost instance Execute the sendDataPacket function
Something like that:
# ServerWebGamePost.Server = server
server.sendDataPacket(identifier, json) #identifier you must obtain from the datapacket that the client gives in its datapacket (it is a String) json is datapacket in json object
# in ServerWebGamePost.Server.ProcessDatapackServer = self.server.serverFat
You can ban IPs with the banIp and unbanIp functions in ServerWebGamePost.Server class (The IP is String and is only that argument)
If you never run filter origins the origin header will be "*" if you run it it will only accept the given origins (Origin Header) The functions addFilterOrigin and removeFilterOrigin in ServerWebGamePost.Server class only accept one string argument.
You must create a new ServerWebGamePost.Server instance
server = ServerWebGamePost.Server(port, imgSrc, processDatapacks)
# port = int(Here you must specify the port where the server opens), imgSrc = String (Directory in string of the server icon type image can be None), processDatapacks = ServerWebGamePost.Server.ProcessDatapackServer extended class(It should NOT be an instance)
Get http.server.HTTPServer:
server.getHttpServer()
just run the stop function in the Server Class
You need to create a callback function.
Something like that:
def processDatapacks(datapack):
# datapack = json
Simply in ServerWebGamePost.Client class Execute the sendDataPacket function
Something like that:
# client = ServerWebGamePost.Client
client.sendDataPacket(packet)
# packet = json
# Remember to also send the identifier key
You must create a new ServerWebGamePost.Client instance
client = ServerWebGamePost.Client(domain, port, isHttps)
# domain = String (server domain or IP)
# port = String (Server port)
# isHttps= boolean (whether the server has HTTPS encryption or not)
client.setProcessDatapacks(callback)
# callback = function(Callback in charge of handling data packets )