Here's something, it just displays the list of players and their cords. Ill update the code more later to get movable characters around on the screen but I have work in the morning.
// Client-side code (Flash/AS2)
var serverURL:String = "http://127.0.0.1:5000/";
var variables:LoadVars = new LoadVars();
var lblMessages:TextField = this.createTextField("lblMessages", this.getNextHighestDepth(), 0, 0,550,400);
variables.id = String(_xmouse + _ymouse); // Unique id can anything, mouse position can be a good chaos
variables.username = "Johnathan";
variables.xCoord = 1;
variables.yCoord = 12;
variables.onLoad = function(success:Boolean):Void {
if (success) {
trace("Data sent successfully");
} else {
trace("Error connecting to the server.");
}
};
variables.onData = function(data:String):Void {
var message:LoadVars = new LoadVars();
message.decode(data);
trace(data);
lblMessages.text = "";
for (var prop in message) {
var debug = prop + " -> "+message[prop];
trace(debug);
lblMessages.text += debug + "\n";
}
variables.sendAndLoad(serverURL, variables, "POST");
}
stop();
variables.sendAndLoad(serverURL, variables, "POST");
# Server-side code (Python/Flask)
from flask import Flask, request, make_response
import time
import urllib.parse
app = Flask(__name__)
# Dictionary to store connected users and their coordinates
connected_users = {}
@app.route('/', methods=['POST'])
def handle_data():
user_id = request.form.get('id', '')
username = request.form.get('username', '') # Include username
x_coord = request.form.get('xCoord', '')
y_coord = request.form.get('yCoord', '')
# Process the data as needed
print("Received data - User ID:", user_id, "Username:", username, "X:", x_coord, "Y:", y_coord)
# Update the dictionary with the user's coordinates
connected_users[user_id] = {'username': username, 'x': x_coord, 'y': y_coord}
# Construct the response in the specified format
response_content = '&'.join([f'id.{index}={urllib.parse.quote(user_id)}&username.{index}={user_data["username"]}&xCoord.{index}={user_data["x"]}&yCoord.{index}={user_data["y"]}'
for index, (user_id, user_data) in enumerate(connected_users.items())])
# Create the response object with the desired content type
response = make_response(response_content)
response.headers['Content-Type'] = 'application/x-www-form-urlencoded'
print("Response - " + response_content)
print("Users - " + str(len(connected_users)))
# Wait for 1/10 of a second before sending the next response
time.sleep(1 / 10.0)
return response
if __name__ == '__main__':
app.run(debug=True)