Suppose there are browsers in the form of clients and there is a server. And they communicate with each other using WebSocket.
As a rule, a simple version of coordination in this version looks like a pack of Iphs both on the client side and on the server side. Customer example:
ws = new WebSocket("wss://site.com:8888/"); ws.onopen = function() { ws.send({'e':"new", 'x':lPlayer.getX(), 'y':lPlayer.getY()}); }; ws.onmessage = function(event){ var msg = JSON.parse(event.data); if(msg.e == 'new'){ var newPlayer = new Player(scene, {x,y,z}, msg.x, msg.y); newPlayer.id = msg.id; newPlayer.init(msg.id); remotePlayers.push(newPlayer); }else if(msg.e == 'move' ){ var movePlayer = playerById(msg.id); movePlayer.set(msg.x, msg.y, msg.z); }else if(msg.e == 'rotate' ){ var rotPlayer = playerById(msg.id); rotPlayer.setA(msg.a); rotPlayer.setB(msg.b); } } Sample server:
var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({port: 8888}); wss.on('connection', function(ws) { clients[max_id] = ws; this.id = max_id; ws.on('message', function(e) { if(ee == 'new'){ var p = new Player(max_id, ex, ey); this.player = p; clients.send_all({'e':"new", 'id':p.id, 'x':px(), 'y':py,'z':pz}); players.push(p); }else if (ee == 'move') { var p = this.player; p.set(ex, ey, ez); clients.send_all({'e':"move", 'id':p.id, 'x':p.getX(), 'y':p.getY(), 'z':p.getZ(), 'msg':'move'}) } Well, in all this, the most important nuance is that any activity of the player always comes from the client, from which a message is sent to the server with sockets, and then the server is transmitted to all other players for coordination.
A bot activity should always produce a server and broadcast to everyone else. And this is just the main dilemma. So far, the idea comes to mind that it is necessary to register in each activity of the players, that is, for each if (ee == 'move') or for each if (ee == 'shot') some kind of bot action.
It might look something like this:
}else if (ee == 'move') { var p = this.player; p.set(ex, ey, ez); clients.send_all({'e':"move", 'id':p.id, 'x':px, 'y':py, 'z':pz}) var bot = this.player.bot; clients.send_all({'e':"move", 'id':bot.id, 'x':bot.x, 'y':bot.y, 'z':bot.z}) } But further on this fantasy ends. The question is how best to organize the movement of the bot and in the architecture of the game?
Perhaps there are already in other languages similar libraries in Python or any other PHP .