/// <summary> /// Event fired when a data is received from the Alchemy Websockets server instance. /// Parses data as JSON and calls the appropriate message or sends an error message. /// </summary> /// <param name="context">The user's connection context</param> public void OnReceive(UserContext context) { try { var json = context.DataFrame.ToString(); RequestToTossServer obj = JsonConvert.DeserializeObject <RequestToTossServer>(json); ResponseFromTossServer r; switch (obj.Type) { case CommandType.RegisterReq: Register(obj.userIdentity, context); break; case CommandType.HeartBeatReq: var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); r = new ResponseFromTossServer() { Type = CommandType.HeartBeatRes }; user.Context.Send(JsonConvert.SerializeObject(r)); break; default: break; } } catch (Exception e) // Bad JSON! For shame. { var r = new ResponseFromTossServer { Type = CommandType.Error, Data = new { e.Message } }; context.Send(JsonConvert.SerializeObject(r)); } }
void cdrSrv_RequestCDREvent(object sender, int cmd, string caller, string callee, int result) { Clean c = new Clean() { caller = caller, callee = callee, result = result }; var u = OnlineUsers.Keys.FirstOrDefault(); ResponseFromTossServer r = null; Debug.WriteLine("ToossServer callee: " + callee); switch (callee) { case "0001": // Make up room request r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomReq, Data = c }; break; case "0002": // Make up room done r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomDone, Data = c }; break; case "0003": // DnD 요청 r = new ResponseFromTossServer() { Type = CommandType.DnDReq, Data = c }; break; case "0004": // DnD 취소 r = new ResponseFromTossServer() { Type = CommandType.DnDCancel, Data = c }; break; case "0005": // 세탁 요청 r = new ResponseFromTossServer() { Type = CommandType.LaundaryReq, Data = c }; break; case "0006": // 세탁 취소 r = new ResponseFromTossServer() { Type = CommandType.LaundaryCancel, Data = c }; break; case "0007": // make up room confirm r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c }; break; case "0008": // 방청소 확인 r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c }; break; default: switch (caller) { case "morning": r = new ResponseFromTossServer() { Type = CommandType.MorningCall, Data = c }; break; default: return; } break; } if (u != null) u.Context.Send(JsonConvert.SerializeObject(r)); }
/// <summary> /// Broadcasts an error message to the client who caused the error /// </summary> /// <param name="errorMessage">Details of the error</param> /// <param name="context">The user's connection context</param> private static void SendError(string errorMessage, UserContext context) { var r = new ResponseFromTossServer { Type = CommandType.Error, Data = new { Message = errorMessage } }; context.Send(JsonConvert.SerializeObject(r)); }
void pmsSrv_ReqPMSSetEvent(PMSServer sender, _pms_data_type pmsdata) { //var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); var u = OnlineUsers.Keys.FirstOrDefault(); ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.Message, Data = pmsdata }; if (u != null) { u.Context.Send(JsonConvert.SerializeObject(r)); } }
/// <summary> /// Register a user's context for the first time with a username, and add it to the list of online users /// </summary> /// <param name="name">The name to register the user under</param> /// <param name="context">The user's connection context</param> private void Register(string identify, UserContext context) { var json = context.DataFrame.ToString(); RequestToTossServer obj = JsonConvert.DeserializeObject <RequestToTossServer>(json); var u = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); u.Identity = obj.userIdentity; //OnlineUsers[u] = obj.userIdentity; ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.RegisterRes }; var sjson = JsonConvert.SerializeObject(r); context.Send(sjson); }
void wsClient_OnConnectedEvent(Object sender, UserContext context) { if (loginstates) return; ResponseFromTossServer data = new ResponseFromTossServer() { Type = Com.Huen.Sockets.CommandType.HeartBeatReq, Data = new _pms_data_type() }; wsClient.Send(JsonConvert.SerializeObject(data)); }
void cdrSrv_RequestCDREvent(object sender, int cmd, string caller, string callee, int result) { Clean c = new Clean() { caller = caller, callee = callee, result = result }; var u = OnlineUsers.Keys.FirstOrDefault(); ResponseFromTossServer r = null; Debug.WriteLine("ToossServer callee: " + callee); switch (callee) { case "0001": // Make up room request r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomReq, Data = c }; break; case "0002": // Make up room done r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomDone, Data = c }; break; case "0003": // DnD 요청 r = new ResponseFromTossServer() { Type = CommandType.DnDReq, Data = c }; break; case "0004": // DnD 취소 r = new ResponseFromTossServer() { Type = CommandType.DnDCancel, Data = c }; break; case "0005": // 세탁 요청 r = new ResponseFromTossServer() { Type = CommandType.LaundaryReq, Data = c }; break; case "0006": // 세탁 취소 r = new ResponseFromTossServer() { Type = CommandType.LaundaryCancel, Data = c }; break; case "0007": // make up room confirm r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c }; break; case "0008": // 방청소 확인 r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c }; break; default: switch (caller) { case "morning": r = new ResponseFromTossServer() { Type = CommandType.MorningCall, Data = c }; break; default: return; } break; } if (u != null) { u.Context.Send(JsonConvert.SerializeObject(r)); } }
/// <summary> /// Register a user's context for the first time with a username, and add it to the list of online users /// </summary> /// <param name="name">The name to register the user under</param> /// <param name="context">The user's connection context</param> private void Register(string identify, UserContext context) { var json = context.DataFrame.ToString(); RequestToTossServer obj = JsonConvert.DeserializeObject<RequestToTossServer>(json); var u = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); u.Identity = obj.userIdentity; //OnlineUsers[u] = obj.userIdentity; ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.RegisterRes }; var sjson = JsonConvert.SerializeObject(r); context.Send(sjson); }
/// <summary> /// Event fired when a data is received from the Alchemy Websockets server instance. /// Parses data as JSON and calls the appropriate message or sends an error message. /// </summary> /// <param name="context">The user's connection context</param> public void OnReceive(UserContext context) { try { var json = context.DataFrame.ToString(); RequestToTossServer obj = JsonConvert.DeserializeObject<RequestToTossServer>(json); ResponseFromTossServer r; switch (obj.Type) { case CommandType.RegisterReq: Register(obj.userIdentity, context); break; case CommandType.HeartBeatReq: var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); r = new ResponseFromTossServer() { Type = CommandType.HeartBeatRes }; user.Context.Send(JsonConvert.SerializeObject(r)); break; default: break; } } catch (Exception e) // Bad JSON! For shame. { var r = new ResponseFromTossServer { Type = CommandType.Error, Data = new { e.Message } }; context.Send(JsonConvert.SerializeObject(r)); } }
void pmsSrv_ReqPMSSetEvent(PMSServer sender, _pms_data_type pmsdata) { //var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single(); var u = OnlineUsers.Keys.FirstOrDefault(); ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.Message, Data = pmsdata }; if (u != null) u.Context.Send(JsonConvert.SerializeObject(r)); }