public virtual void onSnapshot(BinaryReader message) { List <Object> objects = new List <Object>(); objects.Add(message); int numPlayers = message.ReadInt16(); for (int i = 0; i < numPlayers; i++) { int clientId = message.ReadInt16(); JesterLogger.log("clientId: " + clientId); ActionBasedGameLocation location = new ActionBasedGameLocation(); location.clientId = clientId; location.posX = readFloat(message); location.posY = readFloat(message); location.posZ = readFloat(message); location.rotX = readFloat(message); location.rotY = readFloat(message); location.rotZ = readFloat(message); objects.Add(location); } Event event_ = new Event(ActionGameProtocol.SNAPSHOT, objects); eventQueue.addFunction(event_); }
private Client updateSingleClient(BinaryReader message) { int clientId = message.ReadInt16(); JesterLogger.log("Update connected clients, clientId: " + clientId); if (thisClient == null || thisClient.getId() != clientId) { int count = message.ReadInt16(); JesterLogger.log("count bytes: " + count); byte[] strBytes = message.ReadBytes(count); Encoding enc = new UTF8Encoding(true, true); string clientServerObjectName = enc.GetString(strBytes); JesterLogger.log("Update connected clients, len: " + clientServerObjectName.Length + ", name&email: " + clientServerObjectName); int clientStatus = message.ReadByte(); JesterLogger.log("_Update connected clients, status: " + clientStatus); //string[] nameemail = clientServerObjectName.Split('&'); //string name = nameemail[0]; //string email = nameemail[1]; string name = clientServerObjectName; string email = clientServerObjectName; JesterLogger.log("updateOnClientEnter 0"); Client client = new Client(clientId, name, email, clientStatus); clientsMap.Add(clientId, client); JesterLogger.log("updateOnClientEnter 1"); updateOnClientEnter(client, message); JesterLogger.log("updateOnClientEnter 2"); return(client); } else { return(null); } }
public override bool callFunction(int fnc, BinaryReader message, CompletionCallback callback = null) { bool ret = base.callFunction(fnc, message, callback); JesterLogger.log("ActionGameSpace.callFunction, ret: " + ret + ", fnc: " + fnc); if (ret) { return(true); } switch (fnc) { case ActionGameProtocol.SNAPSHOT: JesterLogger.log("ActionGameProtocol.Snapshot"); onSnapshot(message); return(true); case ActionGameProtocol.ACTION: JesterLogger.log("ActionGameProtocol.Action"); onAction(message); return(true); case ActionGameProtocol.MOVE: JesterLogger.log("ActionGameProtocol.Move"); onMove(message); return(true); } return(false); }
public void Login(string userName, string password, string host, int port) { this.userName = userName; this.password = password; client = new SimpleClient(this); JesterLogger.log("EventsHandler.Login(), userName: "******", host: " + host + ", port: " + port); client.login(host, port); }
protected void updateConnectedClients(BinaryReader message) { int numClients = message.ReadInt16(); JesterLogger.log("Update connected clients, numclients: " + numClients); for (int i = 0; i < numClients; i++) { updateSingleClient(message); } }
protected void putGameRobotEnter(BinaryReader message) { RobotInterface robotPlayer = createRobot(message); JesterLogger.log("GameSpace.putGameRobotEnter, getRobotIndex(): " + robotPlayer.getRobotIndex()); robotsMap.Add(robotPlayer.getRobotIndex(), robotPlayer); List <Object> objects = new List <Object>(); objects.Add(robotPlayer); eventQueue.addFunction(new Event(GameProtocol.GAME_ROBOT_ENTER, objects)); }
// Input events ------------------------------------------------------- public void channelJoin(Channel channel) { JesterLogger.log("Channel join: " + channel.getName()); channelsMap.Add(channel.getName(), channel); // chat interface if (chatInterface != null && channel.getName().ToLower().Contains("chat")) { channel.putMessageInterface(chatInterface); chatInterface.onJoinChannel(channel); } }
public void LoginFailed(string reason) { loggedIn = false; JesterLogger.log("EventsHandler.loginFailed, reason: " + reason); login.loginFailed(reason); //List<int> keys = new List<int>(eventListenersMap.Keys); //foreach (int key in keys) //{ // EventListener eventListener = eventListenersMap[key]; // eventListener.loginFailed(reason); //} }
public void Disconnected(bool forced, string message) { JesterLogger.log("EventsHandler.Disconnected, forced: " + forced + ", message: " + message); loggedIn = false; List <int> keys = new List <int>(eventListenersMap.Keys); foreach (int key in keys) { EventListener eventListener = eventListenersMap[key]; eventListener.disconnected(forced, message); } }
public void LoggedIn(byte[] reconnectKey) { loggedIn = true; JesterLogger.log("EventsHandler.LoggedIn()"); login.loginSuccess(reconnectKey); //List<int> keys = new List<int>(eventListenersMap.Keys); //foreach (int key in keys) //{ // EventListener eventListener = eventListenersMap[key]; // eventListener.loginSuccess(reconnectKey); //} }
public void putEventListener(EventListener eventListener) { JesterLogger.log("EventsHandler.putEventListener(), eventListener: " + eventListener + ",,id: " + eventListener.getId()); int id = eventListener.getId(); if (!eventListenersMap.ContainsKey(id)) { eventListenersMap.Add(id, eventListener); } else { JesterLogger.log("EventsHandler.putEventListener() WARNING, adding event as listener again!"); } }
public ClientChannelListener JoinedChannel(ClientChannel clientChannel) { JesterLogger.log("EventsHandler.JoinedChannel, channelName: " + clientChannel.Name); Channel channel = new Channel(clientChannel); List <int> keys = new List <int>(eventListenersMap.Keys); foreach (int key in keys) { EventListener eventListener = eventListenersMap[key]; eventListener.channelJoin(channel); } return(channel); }
protected override void updateOnClientEnter(Client client, BinaryReader additionalInitInfo) { JesterLogger.log("GameSpace.updateOnClientEnter"); GamePlayer player = createGamePlayer(client, additionalInitInfo); if (thisPlayer == null) { this.thisPlayer = player; } client.addPlayer(player); gamePlayersMap.Add(player.getClient().getId(), player); base.updateOnClientEnter(client, additionalInitInfo); }
public void sendEnterMatchMaker(int matchMakerId = -1) { JesterLogger.log("LoginSpace.sendEnterLobby(), lobbyId: " + matchMakerId); MemoryStream m = new MemoryStream(); BinaryWriter bw = new BinaryWriter(m); int idMessageReceiver = -1; // On Server by default LoginMessageReceiver id == -1 bw.Write(idMessageReceiver); byte event_ = LoginProtocol.ENTER_MATCH_MAKER; bw.Write(event_); bw.Write(matchMakerId); clientSession.sessionSend(m); }
public void sessionSend(MemoryStream message) { byte[] bytesMessage = null; //byte[] buffer = new byte[1024]; //using (MemoryStream ms = new MemoryStream()) //{ // int read; // while ((read = message.Read(buffer, 0, buffer.Length)) > 0) // { // ms.Write(buffer, 0, read); // } // bytesMessage = ms.ToArray(); //} bytesMessage = message.ToArray(); JesterLogger.log("EventsHandler.sessionSend(), Count: " + bytesMessage.Length); client.SessionSend(bytesMessage); }
public void notifyCurrentPlayer(Client client, CompletionCallback callback) { JesterLogger.log("TurnGameSpace.notifyCurrentPlayer"); int id = getId(); JesterLogger.log("getId(): " + id); GamePlayer gamePlayer = client.getPlayer(id); JesterLogger.log("GamePlayer: " + gamePlayer); JesterLogger.log("GamePlayer2: " + gamePlayer.getName()); this.currentPlayer = (TurnGamePlayer)gamePlayer; JesterLogger.log("GamePlayer3: " + this.currentPlayer); JesterLogger.log("TurnGameSpace.notifyCurrentPlayer, currentPlayer: " + currentPlayer.getId()); List <Object> objects = new List <Object>(); objects.Add(client); eventQueue.addFunction(new Event(TurnGameProtocol.NOTIFY_CURRENT_PLAYER, objects)); }
public void notifyCurrentPlayerRobot(RobotInterface robot, CompletionCallback callback) { JesterLogger.log("TurnGameSpace.notifyCurrentPlayerRobot(), robot: " + robot); TurnGamePlayer robotPlayer = (TurnGamePlayer)robot; if (robotPlayer == null) { throw new Exception("NullPointerException()"); } JesterLogger.log("TurnGameSpace.notifyCurrentPlayerRobot(), robot:2"); this.currentPlayer = robotPlayer; JesterLogger.log("TurnGameSpace.notifyCurrentPlayerRobot(), robot:3"); List <Object> objects = new List <Object>(); objects.Add(robot); JesterLogger.log("TurnGameSpace.notifyCurrentPlayerRobot(), robot:4"); eventQueue.addFunction(new Event(TurnGameProtocol.NOTIFY_CURRENT_PLAYER_ROBOT, objects)); JesterLogger.log("TurnGameSpace.notifyCurrentPlayerRobot() out"); }
public bool isThisCurrentPlayer() { if (currentPlayer == null) { return(false); } if (currentPlayer.isRobot()) { JesterLogger.log("TurnGameSpace.isThisCurrentPlayer(): " + currentPlayer.isRobot()); return(false); } int id_ = thisPlayer.getClient().getId(); int currId_ = currentPlayer.getClient().getId(); JesterLogger.log("TurnGameSpace.isThisCurrentPlayer(), id: " + id_ + ", currId: " + currId_); return(id_ == currId_); }
public GamePlayer getPlayerWithClientId(int clientId) { JesterLogger.log("GameSpace.getPlayerWithClientId, clientId: " + clientId); JesterLogger.log("GameSpace.getPlayerWithClientId, clientsMapCount: " + clientsMap.Count); int idx = 0; List <int> list = new List <int>(clientsMap.Keys); foreach (int k in list) { JesterLogger.log("Key: " + k + ", idx: " + idx++); } Client client = clientsMap[clientId]; JesterLogger.log("GameSpace.getPlayerWithClientId, client: " + client); GamePlayer gamePlayer = client.getPlayer(getId()); JesterLogger.log("GameSpace.getPlayerWithClientId, gamePlayer: " + gamePlayer); return(gamePlayer); }
protected virtual void updateOnClientEnter(Client client, BinaryReader additionalInitInfo) { JesterLogger.log("updateoncliententer, space, id: " + id); if (thisClient == null) { thisClient = client; if (chatInterface != null) { chatInterface.setClient(thisClient); } } if (parentSpace != null) { parentSpace.onChildEnter(this, client); } List <object> objects = new List <object>(); objects.Add(client); eventQueue.addFunction(new Event(SpaceProtocol.ENTER, objects)); }
public void ReceivedMessage(byte[] message) { JesterLogger.log("EventsHandler.ReceivedMessage_, message: " + message.Length); MemoryStream m = new MemoryStream(); m.SetLength(message.Length); BinaryWriter bw = new BinaryWriter(m); bw.Write(message); bw.Flush(); m.Position = 0; JavaBinaryReader br = new JavaBinaryReader(m); int id = br.ReadInt32(); int fnc = br.ReadByte(); JesterLogger.log("EventsHandler.ReceivedMessage, fnc: " + fnc + ", id: " + id); EventListener eventListener = eventListenersMap[id]; JesterLogger.log("EventsHandler.ReceivedMessage, eventListener: " + eventListener.getId()); eventListener.callFunction(fnc, br); }
public override bool callFunction(int fnc, BinaryReader message, CompletionCallback callback = null) { bool ret = base.callFunction(fnc, message, callback); if (ret) { return(true); } JesterLogger.log("GameSpace.function: " + fnc); switch (fnc) { case GameProtocol.GAME_PLAYER_GIVE_UP: List <Object> objects = new List <Object>(); int clientId = message.ReadInt16(); GamePlayer gamePlayer = getPlayerWithClientId(clientId); objects.Add(gamePlayer); eventQueue.addFunction(new Event(GameProtocol.GAME_PLAYER_GIVE_UP, objects)); clientsMap.Remove(clientId); return(true); case GameProtocol.GAME_PLAYER_FALL: objects = new List <Object>(); clientId = message.ReadInt16(); gamePlayer = getPlayerWithClientId(clientId); objects.Add(gamePlayer); eventQueue.addFunction(new Event(GameProtocol.GAME_PLAYER_FALL, objects)); clientsMap.Remove(clientId); return(true); case GameProtocol.GAME_STARTED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(GameProtocol.GAME_STARTED, objects)); return(true); case GameProtocol.GAME_STOPPED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(GameProtocol.GAME_STOPPED, objects)); return(true); case GameProtocol.GAME_RESULTS: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(GameProtocol.GAME_RESULTS, objects)); return(true); case GameProtocol.UPDATE_SCORE: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(GameProtocol.UPDATE_SCORE, objects)); return(true); case GameProtocol.GAME_FINISHED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(GameProtocol.GAME_FINISHED, objects)); return(true); case GameProtocol.GAME_CAN_RESTART: bool canRestartFlag = message.ReadBoolean(); objects = new List <Object>(); objects.Add(canRestartFlag); eventQueue.addFunction(new Event(GameProtocol.GAME_CAN_RESTART, objects)); return(true); case GameProtocol.GAME_ROBOT_ENTER: putGameRobotEnter(message); return(true); case GameProtocol.GAME_ROBOT_REPLACEMENT: gameRobotReplacement(message); return(true); case GameProtocol.GAME_ROBOT_EXIT: onGameRobotExit(message); return(true); } return(false); }
public static void putSpace(JesterClient.Space space) { JesterLogger.log("SpaceMapping.putSpace: " + space.getId()); getInstance().spaceMapping.Add(space.getId(), space); getInstance().spaceStack.Push(space); }
public static void removeSpace(int id) { JesterLogger.log("SpaceMapping.removeSpace: " + id); getInstance().spaceMapping.Remove(id); getInstance().spaceStack.Pop(); }
public override bool callFunction(int fnc, BinaryReader message, CompletionCallback callback = null) { bool ret = base.callFunction(fnc, message, callback); JesterLogger.log("TurnGameSpace.callFunction, ret: " + ret + ", fnc: " + fnc); if (ret) { return(true); } switch (fnc) { case TurnGameProtocol.NOTIFY_CURRENT_PLAYER: JesterLogger.log("NOTIFY_CURRENT_PLAYER "); int clientId = message.ReadInt16(); JesterLogger.log("clientId: " + clientId); Client client = clientsMap[clientId]; JesterLogger.log("client: " + client); notifyCurrentPlayer(client, callback); return(true); case TurnGameProtocol.NOTIFY_CURRENT_PLAYER_ROBOT: JesterLogger.log("TurnGameSpace.NOTIFY_CURRENT_PLAYER_ROBOT"); int robotIndex = message.ReadByte(); JesterLogger.log("TurnGameSpace.RobotsMap sz: " + robotsMap.Count + ", robotIdx: " + robotIndex); List <int> dellist = new List <int>(robotsMap.Keys); for (int i = 0; i < dellist.Count; i++) { JesterLogger.log("TurnGameSpace.RobotsMap, i: " + i + ", key: " + dellist[i]); } RobotInterface robot = robotsMap[robotIndex]; JesterLogger.log("TurnGameSpace.RobotsMap 2...."); notifyCurrentPlayerRobot(robot, callback); return(true); case TurnGameProtocol.TURN_STARTED: List <Object> objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(TurnGameProtocol.TURN_STARTED, objects)); return(true); case TurnGameProtocol.TURN_FINISHED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(TurnGameProtocol.TURN_FINISHED, objects)); return(true); case TurnGameProtocol.MATCH_STARTED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(TurnGameProtocol.MATCH_STARTED, objects)); return(true); case TurnGameProtocol.MATCH_FINISHED: objects = new List <Object>(); objects.Add(message); eventQueue.addFunction(new Event(TurnGameProtocol.MATCH_FINISHED, objects)); return(true); case TurnGameProtocol.SET_SELECTABLES_BY_PLAYER: int playerId = message.ReadInt32(); bool selectable = message.ReadBoolean(); GamePlayer gamePlayer = gamePlayersMap[id]; objects = new List <Object>(); objects.Add(gamePlayer); objects.Add(selectable); eventQueue.addFunction(new Event(TurnGameProtocol.SET_SELECTABLES_BY_PLAYER, objects)); return(true); case TurnGameProtocol.SET_THIS_PLAYER_SELECTABLES: selectable = message.ReadBoolean(); objects = new List <Object>(); objects.Add(thisPlayer); objects.Add(selectable); eventQueue.addFunction(new Event(TurnGameProtocol.SET_THIS_PLAYER_SELECTABLES, objects)); return(true); } return(false); }