void OnRead(TcpSocketClient client, byte[] buffers) { ThreadCalls(() => { try { var cmd = new BaseCommand(buffers); switch (cmd.Command) { case Commands.Bind_Resp: var bind_resp = new Bind_Resp(buffers); if (bind_resp.Result != CommandError.Success) { PrintLog("绑定验证失败:" + CommandError.GetMessage(bind_resp.Result)); Thread.Sleep(1000); client.Disconnect(); } break; case Commands.Deliver: var deliver = new Deliver(buffers); //新消息提醒 PrintLog("收到一条 " + deliver.UserNumber + " 发来的新消息!"); //绑定消息会话 BindSession(false, deliver.UserNumber, deliver.MessageContent); //发送响应 client.Send(new Deliver_Resp { SequenceNumber = deliver.SequenceNumber, Result = CommandError.Success }.GetBytes()); break; case Commands.Deliver_Resp: var deliver_resp = new Deliver_Resp(buffers); if (deliver_resp.Result != CommandError.Success) { PrintLog("传送消息失败:" + CommandError.GetMessage(deliver_resp.Result)); } break; case Commands.Report: client.Send(new Report_Resp { SequenceNumber = cmd.SequenceNumber, Result = CommandError.Success }.GetBytes()); break; default: break; } PrintLog("接收一条命令:" + Commands.GetString(cmd.Command)); } catch (Exception e) { PrintLog("读取消息出现错误: " + e.Message); } }); }
public static TextComponent Error(int line, CommandError error) { return(new TextComponent($"\n Line {line}: {error.GetMessage()}").WithColour(Colour.BuiltinColours.RED)); }
void OnRead(TcpSocketClient client, byte[] buffers) { ThreadCalls(() => { try { var cmd = new BaseCommand(buffers); switch (cmd.Command) { case Commands.Bind_Resp: var bind_resp = new Bind_Resp(buffers); if (bind_resp.Result != CommandError.Success) { PrintLog("绑定验证失败:" + CommandError.GetMessage(bind_resp.Result)); Thread.Sleep(1000); client.Disconnect(); } break; case Commands.Deliver: var deliver = new Deliver(buffers); //添加接收记录 var sms = new SMS { SPNumber = deliver.SPNumber, UserNumber = deliver.UserNumber, Content = deliver.MessageContent, Time = DateTime.Now, Type = SMSTypes.RECEIVE }; SMSHistory.Add(sms); //绑定会话组 BindGroup(deliver.SPNumber); //绑定会话 if (lbGroup.SelectedItem != null && lbGroup.SelectedItem.ToString() == sms.SPNumber) { BindSession(sms); } else { lbGroup.SelectedItem = deliver.SPNumber; BindSession(deliver.SPNumber); } //新消息提醒 PrintLog("收到一条 " + sms.SPNumber + " 发来的新消息!"); //发送响应 client.Send(new Deliver_Resp { SequenceNumber = deliver.SequenceNumber, Result = CommandError.Success }.GetBytes()); break; case Commands.Deliver_Resp: var deliver_resp = new Deliver_Resp(buffers); if (deliver_resp.Result != CommandError.Success) { PrintLog("传送消息失败:" + CommandError.GetMessage(deliver_resp.Result)); } break; default: break; } PrintLog("接收一条命令:" + Commands.GetString(cmd.Command)); } catch (Exception e) { PrintLog("读取消息出现错误: " + e.Message); } }); }