public void LeaveRoom(string username, string roomName) { IMQDriver mqDriver = GetMQDriver(); string command = Config.GenerateCommand(Config.CMD.LEAVE_ROOM, Thread.CurrentThread.ManagedThreadId, username, roomName); bool hasResponded = false; mqDriver.OnResponseRecieved += (cmd) => { string[] cmdParts = cmd.Split(':'); string cmdType = GetCmdType(Config.CMD.LEAVE_ROOM_RESPONSE); if (cmdParts[0].Equals(cmdType)) { if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId)) { if (!cmdParts[2].ToUpper().Equals("OK")) { throw new FaultException(cmd); } else { hasResponded = true; } } } }; mqDriver.SendCommand(command); Wait(ref hasResponded); mqDriver.ListenerOpen = false; }
private void LockUsername(string username, IMQDriver mqDriver) { string command = Config.GenerateCommand(Config.CMD.VAL_USERNAME, Thread.CurrentThread.ManagedThreadId, username); bool usernameLocked = false; mqDriver.OnResponseRecieved += (cmd) => { string cmdType = GetCmdType(Config.CMD.VAL_USERNAME_REPONSE); string[] cmdParts = cmd.Split(Config.SEPERATOR); if (cmdParts[0].Equals(cmdType)) { if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId)) { if (cmdParts[2].ToUpper().Equals("OK")) { usernameLocked = true; } else { throw new FaultException(cmd); } } } }; mqDriver.SendCommand(command); Wait(ref usernameLocked); }
private void ReleaseUsername(string username, IMQDriver mqDriver) { string command = Config.GenerateCommand(Config.CMD.RELEASE_USERNAME, Thread.CurrentThread.ManagedThreadId, username); mqDriver.SendCommand(command); //mqDriver.CloseConnections(); //TODO: close connections? }
public void JoinRoom(string username, string roomName) { IMQDriver mqDriver = GetMQDriver(); string command = Config.GenerateCommand(Config.CMD.JOIN_ROOM, Thread.CurrentThread.ManagedThreadId, username, roomName); bool hasResponded = false; mqDriver.OnResponseRecieved += (cmd) => { string[] cmdParts = cmd.Split(Config.SEPERATOR); string cmdType = GetCmdType(Config.CMD.JOIN_ROOM_RESPONSE); if (cmdParts[0].Equals(cmdType)) { if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId)) { if (!cmdParts[2].ToUpper().Equals("OK")) { throw new FaultException(cmd); } else { hasResponded = true; } } } }; Wait(ref hasResponded); mqDriver.SendCommand(command); //mqDriver.CloseConnections(); //TODO: close connections? }
public void SendMessage(string username, string roomName, string encryptedMessage) { IMQDriver mqDriver = GetMQDriver(); string command = Config.GenerateCommand(Config.CMD.SEND_MESSAGE, Thread.CurrentThread.ManagedThreadId, username, roomName, encryptedMessage); mqDriver.SendCommand(command); mqDriver.ListenerOpen = false; }
public void SendMessage(string username, string roomName, string encryptedMessage) { IMQDriver mqDriver = GetMQDriver(); string command = Config.GenerateCommand(Config.CMD.SEND_MESSAGE, Thread.CurrentThread.ManagedThreadId, username, roomName, encryptedMessage); mqDriver.SendCommand(command); //mqDriver.CloseConnections(); //TODO: close connections? }
public string[] GetRooms() { IMQDriver mqDriver = GetMQDriver(); string command = Config.GenerateCommand(Config.CMD.REQUEST_ROOMS, Thread.CurrentThread.ManagedThreadId); List <string> rooms = new List <string>(); bool aServerHasResponded = false; mqDriver.OnResponseRecieved += (cmd) => { if (!aServerHasResponded) { string cmdType = GetCmdType(Config.CMD.REQUEST_ROOMS_RESPONSE); string[] cmdParts = cmd.Split(':'); if (cmdParts[0].Equals(cmdType)) { if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId)) { for (int i = 2; i < cmdParts.Length; i++) { rooms.Add(cmdParts[i]); } aServerHasResponded = true; } } } }; mqDriver.SendCommand(command); Wait(ref aServerHasResponded); mqDriver.ListenerOpen = false; return(rooms.ToArray()); }
private void ReleaseUsername(string username, IMQDriver mqDriver) { string command = Config.GenerateCommand(Config.CMD.RELEASE_USERNAME, Thread.CurrentThread.ManagedThreadId, username); mqDriver.SendCommand(command); }