public override void ExecuteCommand(AppSession session, StringPackageInfo requestInfo) { var paramsArray = requestInfo.Body.Split(' '); for (var i = 0; i < paramsArray.Length; i++) { session.Send(paramsArray[i]); } }
static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo) { switch (requestInfo.Key.ToUpper()) { case("ECHO"): session.Send(requestInfo.Body); break; case ("ADD"): session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString()); break; case ("MULT"): var result = 1; foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p))) { result *= factor; } session.Send(result.ToString()); break; } }
static void appServer_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo) { Console.WriteLine(requestInfo.Body); Console.WriteLine(requestInfo.Key); Console.WriteLine(requestInfo.Parameters); }
/// <summary> /// /// </summary> /// <param name="strIpPort_">ip</param> /// <param name="doc_"></param> /// <param name="fromServer_">是否是同组服务器发来的消息,因现在是共用一个处理队列,防止客户端伪造</param> public SessionMessage(AppSession e_, XmlDocument doc_, bool fromRCServer_,String strIpPort_) { _e = e_; _strIpPort = strIpPort_; _doc = doc_; _fromRCServer = fromRCServer_; }
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo) { var result = 1; foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p))) { result *= factor; } session.Send(result.ToString()); }
//@OnMessage public string onMessage(string message, AppSession session) { Console.Error.WriteLine("New message from Client " + session.SessionID + ": " + message); //should echo back whatever is heard from any client to all clients //foreach (Session sess in session.getOpenSessions()) { foreach(AppSession sess in session.AppServer.GetAllSessions()) { if(sess.Connected) { try { //sess.RemoteEndPoint.sendText(message); sess.Send(message); } catch (IOException e) { Console.WriteLine(System.Environment.StackTrace); } } } return null; }
/// <summary> /// 向指定的通信对象发送字节数据 /// </summary> /// <param name="session">连接对象</param> /// <param name="customer">用户的指令头</param> /// <param name="bytes">实际的数据</param> public void SendMessage(AppSession session, int customer, byte[] bytes) { SendBytesAsync(session, HslProtocol.CommandBytes(customer, Token, bytes)); }
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo) { session.Send(requestInfo.Body); }
/// <summary> /// 向指定的通信对象发送字符串数据 /// </summary> /// <param name="session">通信对象</param> /// <param name="customer">用户的指令头</param> /// <param name="str">实际发送的字符串数据</param> public void SendMessage(AppSession session, int customer, string str) { SendBytesAsync(session, HslProtocol.CommandBytes(customer, Token, str)); }
/// <summary> /// 房间变量 /// 对roomId要验证一次 /// 转发给房间的其他人 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> public void doorSetRvars(AppSession session, XmlDocument doc, SessionMessage item) { int roomId = 0; string strIpPort = string.Empty; try { strIpPort = session.RemoteEndPoint.ToString(); //<vars><var n='selectQizi' t='s'><![CDATA[red_pao_1]]></var></vars> XmlNode node = doc.SelectSingleNode("/msg/body"); roomId = int.Parse(node.Attributes["r"].Value); //安全检测 if (!logicHasRoom(roomId)) { return; } if (!logicHasUserInRoom(strIpPort, roomId)) { return; } // XmlNode nodeVars = doc.SelectSingleNode("/msg/body/vars"); // IRoomModel room = logicGetRoom(roomId); IUserModel user = logicGetUser(strIpPort); //save //关于转发数据的合法性,不合法的处理方法需要再研究 int len = nodeVars.ChildNodes.Count; int i = 0; string n = string.Empty; string v = string.Empty; for (i = 0; i < len; i++) { n = nodeVars.ChildNodes[i].Attributes["n"].Value; v = nodeVars.ChildNodes[i].InnerText; RvarsStatus sta; //检测不通过 if (!room.chkVars(n, v, user.Id, ref nodeVars,i,out sta)) { return; } } // n = string.Empty; v = string.Empty; for (i = 0; i < len; i++) { n = nodeVars.ChildNodes[i].Attributes["n"].Value; v = nodeVars.ChildNodes[i].InnerText; room.setVars(n,v); } //转发 string saction = ServerAction.rVarsUpdate; string contentXml = "<room id='" + roomId.ToString() + "'>" + nodeVars.OuterXml + "</room>"; netTurnRoom(strIpPort, roomId, saction, contentXml); //log Log.WriteStrByTurn(SR.Room_displayName + roomId.ToString(), strIpPort, saction, n, nodeVars.InnerText); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorSetRvars", exd.Message, exd.Source, exd.StackTrace); } try { //群发,全部准备可以开始游戏 //判断游戏是否可以开始 logicCheckGameStart(roomId); //群发 logicCheckGameStartFirstChuPai(roomId, strIpPort); //判断游戏是否中断结束,此情况为三轮均不叫,全部踢出房间,不扣金点 logicCheckGameOver_RoomClear(roomId, strIpPort); //群发 //判断游戏是否可以结束 logicCheckGameOver(roomId, strIpPort); } catch (Exception exc) { Log.WriteStrByException(CLASS_NAME, "doorSetRvars", exc.Message, exc.Source ,exc.StackTrace); } }
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo) { ((MyAppServerA)session.AppServer).DespatchMessage(requestInfo[0], requestInfo[1]); }
public void Dereference() { _e = null; _doc = null; }
/// <summary> /// TimedAutoMatch的子函数,成功坐下 /// </summary> /// <param name="room"></param> /// <param name="userSession"></param> private void TimedAutoMatchRoom_Sub_SitDown_Ok(IRoomModel room, AppSession userSession) { try { string svrAction = ServerAction.joinOK; // StringBuilder contentXml = new StringBuilder(); //获取房间的xml输出 //IRoomModel room = logicGetRoom(roomId); string roomXml = room.toXMLString(); //坐下成功不需要code //contentXml.Append("<code>0</code>"); contentXml.Append(roomXml); //回复 Send(userSession, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); //log Log.WriteStrBySend(svrAction, userSession.RemoteEndPoint.ToString()); //转发 uER = UserEnterRoom string svrAction_uER = ServerAction.uER; IUserModel sitDownUser = logicGetUser(userSession.RemoteEndPoint.ToString()); string chairAndUserXml = room.getChair(sitDownUser).toXMLString(); netTurnRoom(userSession.RemoteEndPoint.ToString(), room.Id, svrAction_uER, chairAndUserXml); Log.WriteStrByTurn(SR.Room_displayName + room.Id.ToString(), "", svrAction_uER); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "TimedAutoMatch_Sub_SitDown", exd.Message, exd.Source, exd.StackTrace); } }
void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo) { try { RemoteCommand type = (RemoteCommand)Enum.Parse(typeof(RemoteCommand), requestInfo.Key); LogHelper.WriteLog(typeof(RemoteCommand), "收到消息:" + type.ToString() + requestInfo.Key); switch (type) { case RemoteCommand.Login: CheckLogin(requestInfo); break; case RemoteCommand.SendFrontCurSession: SendCurSessionToBack(); break; case RemoteCommand.ImportFrontLocalSessions: SendCompressedCommand(RemoteCommand.ImportFrontLocalSessions, Game.Instance.LocalSessions, session); break; case RemoteCommand.ImportBack: OnImportBack(session, requestInfo); break; case RemoteCommand.ImportBackNextSession: OnImportBackNextSession(session, requestInfo); break; case RemoteCommand.SendFrontBetRecordIdList: SendBetRecordIdsToBack(); break; case RemoteCommand.SendFrontBetRecord: SendBetRecordToBack(session, requestInfo); break; case RemoteCommand.SendFrontAccount: SendAccountToBack(session, requestInfo); break; case RemoteCommand.ClearFrontAccount: Game.Instance.Manager.ClearFrontAccountByBack(); break; case RemoteCommand.ClearFrontLocalSessions: Game.Instance.Manager.ClearLocalSessions(); break; case RemoteCommand.SetWinner: SetWinner(session, requestInfo); break; case RemoteCommand.KillBig: KillBig(session, requestInfo); break; case RemoteCommand.ExtraWaybill: ExtraWaybill(); break; case RemoteCommand.ShutdownFront: ControlBoard.Instance.ShutdownComputer(); break; case RemoteCommand.BreakdownFront: ControlBoard.Instance.BreakdownGame(); break; case RemoteCommand.LockFront: Game.Instance.SetGameLock(); if (appSession.Connected && Login) { SendData(RemoteCommand.LockFrontOK, "", appSession); } break; case RemoteCommand.UnlockFront: Game.Instance.SetGameUnlock(); if (appSession.Connected && Login) { SendData(RemoteCommand.UnlockFrontOK, "", appSession); } break; case RemoteCommand.ModifyFrontPassword: ModifyFrontPassword(session, requestInfo); break; case RemoteCommand.ModifyFrontSetting: ModifyFrontSetting(session, requestInfo); break; default: break; } } catch (Exception ex) { LogHelper.WriteLog(typeof(Object), "UnobservedTaskException:" + ex.Message + ex.StackTrace); //throw; } }
public CallbackController(SessionStateProvider baseSession) : base() { _mySession = new AppSession(baseSession); }
void appServer_SessionClosed(AppSession session, SuperSocket.SocketBase.CloseReason value) { Login = false; Game.Instance.CoreTimer.StopWebTimer(); session.Send("服务已关闭"); }
private void NetComplex_AcceptString(AppSession stateone, HslCommunication.NetHandle handle, string data) { // 接收到客户端发来的数据时触发 }
/// <summary> /// 处理请求接收连接后的方法 /// </summary> /// <param name="obj">Accpt对象</param> protected override void ThreadPoolLogin(object obj) { if (obj is Socket socket) { // 接收一条信息,指定当前请求的数据订阅信息的关键字 OperateResult <int, string> receive = ReceiveStringContentFromSocket(socket); if (!receive.IsSuccess) { return; } // 判断当前的关键字在服务器是否有消息发布 if (!IsPushGroupOnline(receive.Content2)) { SendStringAndCheckReceive(socket, 1, "当前订阅的关键字不存在"); LogNet?.WriteWarn(ToString( ), "当前订阅的关键字不存在"); socket?.Close( ); return; } SendStringAndCheckReceive(socket, 0, ""); // 允许发布订阅信息 AppSession session = new AppSession( ); session.KeyGroup = receive.Content2; session.WorkSocket = socket; try { session.IpEndPoint = (System.Net.IPEndPoint)socket.RemoteEndPoint; session.IpAddress = session.IpEndPoint.Address.ToString( ); } catch (Exception ex) { LogNet?.WriteException(ToString( ), "Ip信息获取失败", ex); } try { socket.BeginReceive(session.BytesHead, 0, session.BytesHead.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), session); } catch (Exception ex) { LogNet?.WriteException(ToString( ), "开启信息接收失败", ex); return; } LogNet?.WriteDebug(ToString( ), $"客户端 [ {session.IpEndPoint} ] 上线"); PushGroupClient push = GetPushGroupClient(receive.Content2); if (push != null) { System.Threading.Interlocked.Increment(ref onlineCount); push.AddPushClient(session); dicSendCacheLock.Enter( ); if (dictSendHistory.ContainsKey(receive.Content2)) { SendString(session, dictSendHistory[receive.Content2]); } dicSendCacheLock.Leave( ); } } }
public ImagesVm(AppSession session) : base(session) { }
private static void msgTimedEvent(object source, ElapsedEventArgs e) { try { SmqOppResult ruCount = msgList.Opp(QueueMethod.Count, null); int len = ruCount.count; for (int i = 0; i < len; i++) { #region 获取消息及Session SmqOppResult ruShift = msgList.Opp(QueueMethod.Shift, null); if (!ruShift.oppSucess) { continue; } SessionMessage item = ruShift.item; // XmlDocument doc = item.doc(); string strIpPort = item.strIpPort(); string action = item.action(); SocketConnector session = null; AppSession c = null; // if (!item.fromServer) { if (DdzLogic.getInstance().netHasSession(strIpPort)) { c = DdzLogic.getInstance().netGetSession(strIpPort); }//end if } else { //if (item.fromDBServer) //{ // session = DdzLogic.DBConnector.getSocket(); //}else if (item.fromRCServer) //{ session = DdzLogic.getInstance().RCConnector;//.getSocket(); //}//end if } #endregion #region 客户端协议处理 if (!item.fromServer) { if (ClientAction.verChk == action) { DdzLogic.getInstance().doorVerChk(c, doc, item); continue; } if (ClientAction.loadDBType == action) { DdzLogic.getInstance().doorLoadDBType(c, doc); continue; } if (ClientAction.hasReg == action) { DdzLogic.getInstance().doorHasReg(c, doc, item); continue; } if (ClientAction.reg == action) { DdzLogic.getInstance().doorReg(c, doc, item); continue; } if (ClientAction.login == action) { DdzLogic.getInstance().doorLogin(c, doc, item); continue; } if (ClientAction.heartBeat == action) { DdzLogic.getInstance().doorHeartBeat(c, doc, item); continue; } if (ClientAction.loadG == action) { DdzLogic.getInstance().doorLoadG(c, doc, item); continue; } if (ClientAction.loadD == action) { DdzLogic.getInstance().doorLoadD(c, doc, item); continue; } if (ClientAction.listModule == action) { DdzLogic.getInstance().doorListModule(c, doc, item); continue; } if (ClientAction.listRoom == action) { DdzLogic.getInstance().doorListRoom(c, doc, item); continue; } if (ClientAction.joinRoom == action) { DdzLogic.getInstance().doorJoinRoom(c, doc, item); continue; } if (ClientAction.joinReconnectionRoom == action) { DdzLogic.getInstance().doorJoinReconnectionRoom(c, doc, item); continue; } if (ClientAction.autoJoinRoom == action) { DdzLogic.getInstance().doorAutoJoinRoom(c, doc, item); continue; } if (ClientAction.autoMatchRoom == action) { DdzLogic.getInstance().doorAutoMatchRoom(c, doc, item); continue; } if (ClientAction.pubMsg == action) { DdzLogic.getInstance().doorPubMsg(c, doc, item); continue; } if (ClientAction.pubAuMsg == action) { DdzLogic.getInstance().doorPubAuMsg(c, doc, item); continue; } if (ClientAction.setRvars == action) { DdzLogic.getInstance().doorSetRvars(c, doc, item); continue; } if (ClientAction.setMvars == action) { DdzLogic.getInstance().doorSetMvars(c, doc, item); continue; } if (ClientAction.setModuleVars == action) { DdzLogic.getInstance().doorSetModuleVars(c, doc, item); continue; } if (ClientAction.leaveRoom == action) { DdzLogic.getInstance().doorLeaveRoom(c, doc, item); continue; } if (ClientAction.leaveRoomAndGoHallAutoMatch == action) { DdzLogic.getInstance().doorLeaveRoomAndGoHallAutoMatch(c, doc, item); continue; } if (ClientAction.sessionClosed == action) { DdzLogic.getInstance().logicSessionClosed(strIpPort); continue; } } else { // if (ServerAction.needProof == action) { DdzRCLogic.getInstance().doorNeedProof(session, doc, item); continue; } if (ServerAction.proofOK == action) { DdzRCLogic.getInstance().doorProofOK(session, doc, item); continue; } if (ServerAction.proofKO == action) { DdzRCLogic.getInstance().doorProofKO(session, doc, item); continue; } if (ServerAction.loadDBTypeOK == action) { DdzRCLogic.getInstance().doorLoadDBTypeOK(session, doc, item); continue; } if (ServerAction.regOK == action) { DdzRCLogic.getInstance().doorRegOK(session, doc, item); continue; } if (ServerAction.regKO == action) { DdzRCLogic.getInstance().doorRegKO(session, doc, item); continue; } if (ServerAction.logOK == action) { DdzRCLogic.getInstance().doorLogOK(session, doc, item); continue; } if (ServerAction.logKO == action) { DdzRCLogic.getInstance().doorLogKO(session, doc, item); continue; } if (ServerAction.hasRegOK == action) { DdzRCLogic.getInstance().doorHasRegOK(session, doc, item); continue; } if (ServerAction.hasRegKO == action) { DdzRCLogic.getInstance().doorHasRegKO(session, doc, item); continue; } if (ServerAction.needProof == action) { DdzRCLogic.getInstance().doorNeedProof(session, doc, item); continue; } if (ServerAction.proofOK == action) { DdzRCLogic.getInstance().doorProofOK(session, doc, item); continue; } if (ServerAction.proofKO == action) { DdzRCLogic.getInstance().doorProofKO(session, doc, item); continue; } if (ServerAction.loadGOK == action) { DdzRCLogic.getInstance().doorLoadGOK(session, doc, item); continue; } // if (ServerAction.chkEveryDayLoginAndGetOK == action) { DdzRCLogic.getInstance().doorChkEveryDayLoginAndGetOK(session, doc, item); continue; } } #endregion //Logger.WriteStr("无效协议号:" + action); Log.WriteStr(SR.GetString(SR.Invalid_protocol_num, action)); }//end for // DdzLogic.getInstance().TimedAutoMatchRoom(); DdzLogic.getInstance().TimedWaitReconnection(); DdzLogic.getInstance().TimedChkHeartBeat(); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "msgTimedEvent", exd.Message, exd.StackTrace); } }
public void doorAutoMatchRoom(AppSession session, XmlDocument doc, SessionMessage item) { try { int tab = 0; // XmlNode node = doc.SelectSingleNode("/msg/body/room"); string old = node.Attributes["old"].Value; XmlNode node2 = doc.SelectSingleNode("/msg/body/tab"); tab = Convert.ToInt32(node2.ChildNodes[0].InnerText); // string strIpPort = session.RemoteEndPoint.ToString(); // int roomOldId = Convert.ToInt32(old); AutoMatchRoomModel amr = new AutoMatchRoomModel(strIpPort, tab, roomOldId); // if (!getAutoMatchWaitList().containsKey(strIpPort)) { getAutoMatchWaitList().put(strIpPort, amr); }else { //覆盖数据 getAutoMatchWaitList().put(strIpPort,amr); } } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorAutoMatchRoom", exd.Message, exd.Source, exd.StackTrace); } }
protected override void OnNewSessionConnected(AppSession session) { base.OnNewSessionConnected(session); session.Send("Welcome to SuperSocket FixedHeaderReceive Server."); }
/// <summary> /// 服务器主动发离开房间 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> public void doorLeaveRoom_Svr(AppSession session, XmlDocument doc) { try { //1.查询是否有空位 //2.坐下 XmlNode node = doc.SelectSingleNode("/msg/body/room"); string roomId = node.Attributes["id"].Value; //sr = server response string srAction = string.Empty; string contentXml = string.Empty; //尝试退出 logicLeaveRoom_Svr(session.RemoteEndPoint.ToString()); //回复 srAction = ServerAction.leaveRoom; contentXml = "<rm id='" + roomId + "'/>"; Send(session, XmlInstruction.fengBao(srAction, contentXml) ); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorLeaveRoom_Svr", exd.Message, exd.Source, exd.Message); } }
void appServer_SessionClosed(AppSession session, CloseReason value) { }
/// <summary> /// 一个user To 另一个user的即时打开邮件系统 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> public void doorSetMvars(AppSession session, XmlDocument doc, SessionMessage item) { try { string strIpPort = session.RemoteEndPoint.ToString(); XmlNode node = doc.SelectSingleNode("/msg/body"); string roomId = node.Attributes["r"].Value; XmlNode node2 = doc.SelectSingleNode("/msg/body/vars"); //安全检测 if (!logicHasRoom(int.Parse(roomId)) ) { return; } // IRoomModel room = logicGetRoom(int.Parse(roomId)); //check if (logicHasUser(strIpPort)) { IUserModel fromUser = logicGetUser(strIpPort); //<val n="5a105e8b9d40e1329780d62ea2265d8a" t="s"><![CDATA[askJoinRoom,100]]></val> for (int i = 0; i < node2.ChildNodes.Count; i++) { string n = node2.ChildNodes[i].Attributes["n"].Value; string v = node2.ChildNodes[i].InnerText; //使用拷贝的参数 IUserModel fromUserCpy = UserModelFactory.Create(fromUser.getStrIpPort(), fromUser.Id, 0, fromUser.getSex(), fromUser.getAccountName(), fromUser.getNickName(), fromUser.getBbs(), fromUser.getHeadIco() ); if (logicHasUserById(v)) { IUserModel toUser = logicGetUserById(v); IUserModel toUserCpy = UserModelFactory.Create(toUser.getStrIpPort(), toUser.Id, 0, toUser.getSex(), toUser.getAccountName(), toUser.getNickName(), toUser.getBbs(), toUser.getHeadIco() ); //Mail().setMvars(fromUserCpy, // toUserCpy, // n, // room.Tab.ToString() + "," + room.Id.ToString() + "," + room.getDig().ToString() + "," + room.getCarryg().ToString() // ); } else { //离线存储 } }//end for }//end if //发送 netSendMail(); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorSetMvars", exd.Message, exd.Source, exd.Message); } }
void appServer_NewSessionConnected(AppSession session) { }
public override void ExecuteCommand(AppSession session, StringPackageInfo requestInfo) { session.Close(); }
private static bool ExistCurrent() { return(AppSession.GetItem <DataContext>(_sessionKey) != null); }
/// <summary> /// 版本号检查 /// <开头为回 xml /// %开头为回 字符串 /// {开头为回 json /// </summary> /// <param name="s"></param> /// <param name="xml"></param> /// 不需要同步 public void doorVerChk(AppSession session, XmlDocument doc, SessionMessage item) { try { //doc //<msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg> XmlNode node = doc.SelectSingleNode("/msg/body/ver"); // int clientVer = int.Parse(node.Attributes["v"].Value); //不检查版本号 string saction = string.Empty; //不能低于230 if (clientVer >= 230) { saction = ServerAction.apiOK; } else { saction = ServerAction.apiKO; } //回复 Send(session, XmlInstruction.fengBao(saction, "") ); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorVerChk", exd.Message,exd.Source,exd.StackTrace); } }
public MainVm(AppSession session) : base(session) { Trace.TraceInformation($"new MainVm({session.Id})"); StateMessage = "loading..."; StartUpdates(); }
/// <summary> /// 获取大厅的房间列表 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// 不需要同步 public void doorListRoom(AppSession session, XmlDocument doc, SessionMessage item) { try { //var string svrAction = string.Empty; StringBuilder contentXml = new StringBuilder(); int tab = 0; //read XmlNode node = doc.SelectSingleNode("/msg/body"); tab = Convert.ToInt32(node.ChildNodes[0].InnerText); //验证tab合法性 if (!logicHasTab(tab)) { return; } //send svrAction = ServerAction.listHallRoom; // ITabModel tabModel = logicGetTab(tab); contentXml.Append("<t id='"); contentXml.Append(tabModel.Tab.ToString()); contentXml.Append("' autoMatchMode='"); contentXml.Append(tabModel.getTabAutoMatchMode()); contentXml.Append("' >"); // foreach (int key in roomList.Keys) { IRoomModel room = (IRoomModel)roomList.get(key); if (room.Tab == tab) { contentXml.Append("<r id='"); contentXml.Append(room.Id.ToString()); //为空则由客户端指定名字,如房间1 contentXml.Append("' n='"); contentXml.Append(room.getName()); contentXml.Append("' p='"); contentXml.Append(room.getSomeBodyChairCount().ToString()); contentXml.Append("' dg='"); contentXml.Append(room.getDig()); contentXml.Append("' cg='"); contentXml.Append(room.getCarryg()); contentXml.Append("' />"); } } contentXml.Append("</t>"); //回复 Send(session, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); //log Log.WriteStrBySend(svrAction, session.RemoteEndPoint.ToString()); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorListRoom", exd.Message,exd.Source,exd.StackTrace); } }
public override void ExecuteCommand(AppSession session, StringCommandInfo commandInfo) { ((MyAppServerA)session.AppServer).DespatchMessage(commandInfo[0], commandInfo[1]); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// <param name="item"></param> public void doorJoinReconnectionRoom(AppSession session, XmlDocument doc, SessionMessage item) { try { //1.查询断线重连房间 //2.坐下 XmlNode node = doc.SelectSingleNode("/msg/body/room"); string roomId = node.Attributes["id"].Value; //房间密码暂不启用 string pwd = node.Attributes["pwd"].Value; string old = node.Attributes["old"].Value; // if(!logicHasUser(session.RemoteEndPoint.ToString())) { return; } IUserModel user = logicGetUser(session.RemoteEndPoint.ToString()); // string saction = string.Empty; StringBuilder contentXml = new StringBuilder(); StringBuilder filterContentXml = new StringBuilder(); string roomXml = string.Empty; string filterRoomXml = string.Empty; //重新对roomId赋值 roomId = "-1"; //search IRoomModel room = null; foreach (int key in roomList.Keys) { // room = (IRoomModel)roomList.get(key); if (room.isWaitReconnection) { if (room.WaitReconnectionUser.Id == user.Id) { roomId = room.Id.ToString(); break; } } } //不尝试退出当前的房间 //进入断线重连房间 if ("-1" != roomId && null != room) { #region 尝试坐下 ToSitDownStatus sitDownStatus; bool sitDown = logicHasIdleChairAndSitDown(int.Parse(roomId), session.RemoteEndPoint.ToString(), out sitDownStatus); if (sitDown) { // room.setWaitReconnection(null); // saction = ServerAction.joinOK; //获取房间的xml输出 //IRoomModel room = logicGetRoom(int.Parse(roomId)); roomXml = room.toXMLString(); roomXml = room.getFilterContentXml(session.RemoteEndPoint.ToString(), roomXml); //坐下成功不需要status //contentXml.Append("<status>0</status>"); contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(saction, contentXml.ToString()) ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); //恢复 Send(session, XmlInstruction.fengBao(ServerAction.joinReconnectionOK, contentXml.ToString()) ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); //转发 uER = UserEnterRoom string saction_uER = ServerAction.uER; IUserModel sitDownUser = logicGetUser(session.RemoteEndPoint.ToString()); string chairAndUserXml = room.getChair(sitDownUser).toXMLString(); netTurnRoom(session.RemoteEndPoint.ToString(), int.Parse(roomId), saction_uER, chairAndUserXml); Log.WriteStrByTurn(SR.Room_displayName + roomId, "", saction_uER); //转发 waitReconnectionEnd netTurnRoom(session.RemoteEndPoint.ToString(), int.Parse(roomId), ServerAction.userWaitReconnectionRoomEnd, chairAndUserXml); Log.WriteStrByTurn(SR.Room_displayName + roomId, "", ServerAction.userWaitReconnectionRoomEnd); } else { saction = ServerAction.joinKO; //获取房间的xml输出 roomXml = logicGetRoom(int.Parse(roomId)).toXMLString(); if (sitDownStatus == ToSitDownStatus.NoIdleChair1) { //code 比 status 字符个数少,而且as3 help里很多也用的是code contentXml.Append("<code>1</code>"); } else if (sitDownStatus == ToSitDownStatus.ErrorRoomPassword2) { contentXml.Append("<code>2</code>"); } else { contentXml.Append("<code>3</code>"); } contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(saction, contentXml.ToString()) ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); }//end if #endregion } else { #region 没有断线重连的房间 saction = ServerAction.joinReconnectionKO; //回复 Send(session, XmlInstruction.fengBao(saction, "") ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); #endregion } } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorJoinRoom", exd.Message, exd.Source, exd.StackTrace); } }
public Resource Get(AppSession session, string resourceName, Dictionary<string, string> parameters) { var resourceExtension = Path.GetExtension(resourceName); return new Resource(resourceName, "test://TestResourceLoader.content", ResourceType.GetByExtension(resourceExtension), _content, Resource.Cache.None); }
private void NetComplex_ClientOffline(AppSession session, string object2) { // 客户端下线的时候触发方法 RemoveOnLine(session.ClientUniqueID); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// <param name="item"></param> public void doorListModule(AppSession session, XmlDocument doc, SessionMessage item) { try { //var string svrAction = string.Empty; StringBuilder contentXml = new StringBuilder(); //send svrAction = ServerAction.listModule; contentXml.Append("<module>"); //module list //foreach (int key in roomList.Keys) //{ contentXml.Append("<m n='"); contentXml.Append(DdzLogic_Toac.name); contentXml.Append("' run='"); contentXml.Append(DdzLogic_Toac.turnOver_a_Card_module_run.ToString()); // contentXml.Append("' g1='"); contentXml.Append(DdzLogic_Toac.g1); contentXml.Append("' g2='"); contentXml.Append(DdzLogic_Toac.g2); contentXml.Append("' g3='"); contentXml.Append(DdzLogic_Toac.g3); contentXml.Append("' />"); //} contentXml.Append("</module>"); //回复 Send(session, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); //log Log.WriteStrBySend(svrAction, session.RemoteEndPoint.ToString()); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorListModule", exd.Message, exd.Source, exd.StackTrace); } }
/// <summary> /// Says the welcome information when a client connectted. /// </summary> protected virtual void StartSession() { AppSession.StartSession(); }
/// <summary> /// 加入房间 /// </summary> /// <param name="clientTmp"></param> /// <param name="xml"></param> /// <param name="clients"></param> public void doorJoinRoom(AppSession session, XmlDocument doc, SessionMessage item) { try { //1.查询是否有空位 //2.坐下 XmlNode node = doc.SelectSingleNode("/msg/body/room"); string roomId = node.Attributes["id"].Value; //房间密码暂不启用 string pwd = node.Attributes["pwd"].Value; string old = node.Attributes["old"].Value; // string saction = string.Empty; StringBuilder contentXml = new StringBuilder(); string roomXml = string.Empty; //验证roomId合法性 if (!logicHasRoom(int.Parse(roomId))) { return; } //尝试退出当前的房间 //这个一般是针对外挂, //根据客户端的old来退出当前的房间 //用户只能身在某一个房间中 if (logicHasRoom(int.Parse(old))) { if (logicHasUserInRoom(session.RemoteEndPoint.ToString(), int.Parse(old))) { logicLeaveRoom(session.RemoteEndPoint.ToString()); } } #region 尝试坐下 ToSitDownStatus sitDownStatus; bool sitDown = logicHasIdleChairAndSitDown(int.Parse(roomId), session.RemoteEndPoint.ToString(), out sitDownStatus); if (sitDown) { saction = ServerAction.joinOK; //获取房间的xml输出 IRoomModel room = logicGetRoom(int.Parse(roomId)); roomXml = room.toXMLString(); //坐下成功不需要status //contentXml.Append("<status>0</status>"); contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(saction, contentXml.ToString()) ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); //转发 uER = UserEnterRoom string saction_uER = ServerAction.uER; IUserModel sitDownUser = logicGetUser(session.RemoteEndPoint.ToString()); string chairAndUserXml = room.getChair(sitDownUser).toXMLString(); netTurnRoom(session.RemoteEndPoint.ToString(), int.Parse(roomId), saction_uER, chairAndUserXml); Log.WriteStrByTurn(SR.Room_displayName + roomId, "", saction_uER); } else { saction = ServerAction.joinKO; //获取房间的xml输出 roomXml = logicGetRoom(int.Parse(roomId)).toXMLString(); if (sitDownStatus == ToSitDownStatus.NoIdleChair1) { //code 比 status 字符个数少,而且as3 help里很多也用的是code contentXml.Append("<code>1</code>"); } else if (sitDownStatus == ToSitDownStatus.ErrorRoomPassword2) { contentXml.Append("<code>2</code>"); } else { contentXml.Append("<code>3</code>"); } contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(saction, contentXml.ToString()) ); // Log.WriteStrBySend(saction, session.RemoteEndPoint.ToString()); }//end if #endregion } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorJoinRoom", exd.Message, exd.Source, exd.StackTrace); } }
public override void ExecuteCommand(AppSession session, StringPackageInfo requestInfo) { ((MyAppServerA)session.AppServer).DespatchMessage(requestInfo[0], requestInfo[1]); }
/// <summary> /// 自动加入房间 /// 查找时注意tab种类,是否为密码房间 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// public void doorAutoJoinRoom(AppSession session, XmlDocument doc, SessionMessage item) { try { //var string svrAction = string.Empty; StringBuilder contentXml = new StringBuilder(); string roomXml = string.Empty; int tab = 0; // XmlNode node = doc.SelectSingleNode("/msg/body/room"); string old = node.Attributes["old"].Value; XmlNode node2 = doc.SelectSingleNode("/msg/body/tab"); tab = Convert.ToInt32(node2.ChildNodes[0].InnerText); //尝试退出当前的房间 //这个一般是针对外挂, //根据客户端的old来退出当前的房间 //用户只能身在某一个房间中 if (logicHasRoom(int.Parse(old))) { if (logicHasUserInRoom(session.RemoteEndPoint.ToString(), int.Parse(old))) { logicLeaveRoom(session.RemoteEndPoint.ToString()); } } //尝试坐下 ToSitDownStatus sitDownStatus = ToSitDownStatus.ProviderError3; bool sitDown = false; int roomId = -1; int matchLvl = 1; //自动匹配差1人 foreach (int key in roomList.Keys) { IRoomModel room = (IRoomModel)roomList.get(key); if (room.Tab == tab) { roomId = room.Id; //自动匹配原则是 差1人的游戏最佳 //所以这里不能单单只是坐下,要做在差一人的坐位上 sitDown = logicHasIdleChairAndMatchSitDown(roomId, matchLvl, session.RemoteEndPoint.ToString(), false, out sitDownStatus); if (sitDown) { break; }//end if }//end if }//end for //自动匹配差2人 if (!sitDown) { matchLvl++; foreach (int key2 in roomList.Keys) { IRoomModel room2 = (IRoomModel)roomList.get(key2); if (room2.Tab == tab) { roomId = room2.Id; //自动匹配原则是 差1人的游戏最佳 //所以这里不能单单只是坐下,要做在差一人的坐位上 sitDown = logicHasIdleChairAndMatchSitDown(roomId, matchLvl, session.RemoteEndPoint.ToString(), false, out sitDownStatus); if (sitDown) { break; }//end if }//end if }//end for }//end if //自动匹配差3人 if (!sitDown) { matchLvl++; foreach (int key3 in roomList.Keys) { IRoomModel room3 = (IRoomModel)roomList.get(key3); if (room3.Tab == tab) { roomId = room3.Id; //自动匹配原则是 差1人的游戏最佳 //所以这里不能单单只是坐下,要做在差一人的坐位上 sitDown = logicHasIdleChairAndMatchSitDown(roomId, matchLvl, session.RemoteEndPoint.ToString(), false, out sitDownStatus); if (sitDown) { break; }//end if }//end if }//end for }//end if if (sitDown) { svrAction = ServerAction.joinOK; //获取房间的xml输出 IRoomModel room = logicGetRoom(roomId); roomXml = room.toXMLString(); //坐下成功不需要code //contentXml.Append("<code>0</code>"); contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); //log Log.WriteStrBySend(svrAction, session.RemoteEndPoint.ToString()); //转发 uER = UserEnterRoom string svrAction_uER = ServerAction.uER; IUserModel sitDownUser = logicGetUser(session.RemoteEndPoint.ToString()); string chairAndUserXml = room.getChair(sitDownUser).toXMLString(); netTurnRoom(session.RemoteEndPoint.ToString(), roomId, svrAction_uER, chairAndUserXml); Log.WriteStrByTurn(SR.Room_displayName + roomId.ToString(), "", svrAction_uER); } else { // svrAction = ServerAction.joinKO; //获取房间的xml输出 roomXml = logicGetRoom(roomId).toXMLString(); if (sitDownStatus == ToSitDownStatus.NoIdleChair1) { //code 比 status 字符个数少,而且as3 help里很多也用的是code contentXml.Append("<code>1</code>"); } else if (sitDownStatus == ToSitDownStatus.ErrorRoomPassword2) { contentXml.Append("<code>2</code>"); } else { contentXml.Append("<code>3</code>"); } contentXml.Append(roomXml); //回复 Send(session, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); // Log.WriteStrBySend(svrAction, session.RemoteEndPoint.ToString()); }//end if } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorAutoJoinRoom", exd.Message, exd.Source, exd.StackTrace); } }
protected virtual void ExecuteCommand(TCommandInfo commandInfo) { AppSession.ExecuteCommand(AppSession, commandInfo); }
private void TimedAutoMatchRoom_Sub_Match(ref IRoomModel room, AutoMatchRoomModel amr, IUserModel user, AppSession userSession, ref ToSitDownStatus sitDownStatus, ref bool sitDown, ref int roomId, int matchLvl) { try { foreach (int roomKey in roomList.Keys) { room = (IRoomModel)roomList.get(roomKey); //自动匹配差1人 if (amr.Tab == room.Tab) { roomId = room.Id; //不可为上次的房间,否则会因三人中的二人未退出,又匹配到该房间 if (amr.getRoomOldId() == roomId) { continue; } //不可为正在游戏中的房间 if (room.hasGamePlaying()) { continue; } //不可为断线重连中的房间 if (room.isWaitReconnection) { continue; } //不可为有尸体的房间 if (logicChkRoomByDeadPeople(roomId)) { continue; } //自动匹配原则是 差1人的游戏最佳 //所以这里不能单单只是坐下,要做在差一人的坐位上 sitDown = logicHasIdleChairAndMatchSitDown(roomId, matchLvl, //user.getStrIpPort(), userSession.RemoteEndPoint.ToString(), true, out sitDownStatus); if (sitDown) { TimedAutoMatchRoom_Sub_SitDown_Ok(room, userSession); break; }//end if }//end if }//end for } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "TimedAutoMatchRoom_Sub_Match", exd.Message, exd.Source, exd.StackTrace); } }
/// <summary> /// Says the welcome information when a client connectted. /// </summary> protected virtual void StartSession() { AppSession.LastActiveTime = DateTime.Now; AppSession.StartSession(); }
/// <summary> /// 获取空闲的用户列表 /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// 不需要同步 public void doorLoadD(AppSession session, XmlDocument doc, SessionMessage item) { try { //var string svrAction = string.Empty; StringBuilder contentXml = new StringBuilder(); //send svrAction = ServerAction.dList; // List<string> userStrIpPortList = CLIENTAcceptor.getUserList(); // List<string> idleList = new List<string>(); // int i = 0; int len = userStrIpPortList.Count; //找出空闲的用户 for (i = 0; i < len; i++) { //if (logicHasUser(userStrIpPortList[i])) //{ bool userInRoom = false; //-- foreach (int key in roomList.Keys) { IRoomModel room = roomList.get(key); //logicHasUserInRoom if (logicQueryUserInRoom(userStrIpPortList[i], room.Id)) { userInRoom = true; break; } }//end for if (!userInRoom) { //idleList.Add(logicGetUser(userStrIpPortList[i])); idleList.Add(userStrIpPortList[i]); } //-- //}//end if }//end for //随机抽取10个 //用户觉得10个太少,本人认为如改成全部或100个太多,现改为30 //刷新时间则客户端控制 //if (idleList.Count > 10) //30 现改为 50 //现改为60 int IDLE_LIST_MAX = 100;//60; if (idleList.Count > IDLE_LIST_MAX) { Random r = new Random(RandomUtil.GetRandSeed()); //while (idleList.Count > 10) while (idleList.Count > IDLE_LIST_MAX) { idleList.RemoveAt(r.Next(idleList.Count)); } } //封包 len = idleList.Count; for (i = 0; i < len; i++) { // contentXml.Append((idleList[i] as IUserModel).toXMLString()); // if (logicHasUser(idleList[i])) { IUserModel idleUser = logicGetUser(idleList[i]); contentXml.Append(idleUser.toXMLString()); } } //回复 Send(session, XmlInstruction.fengBao(svrAction, contentXml.ToString()) ); //log Log.WriteStrBySend(svrAction, session.RemoteEndPoint.ToString()); } catch (Exception exd) { Log.WriteStrByException("Logic", "doorLoadD", exd.Message, exd.Source, exd.Message); } }
protected virtual void HandleExceptionalError(Exception e) { AppSession.HandleExceptionalError(e); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// <param name="item"></param> public void doorLeaveRoomAndGoHallAutoMatch(AppSession session, XmlDocument doc, SessionMessage item) { try { //1.查询是否有空位 //2.坐下 XmlNode node = doc.SelectSingleNode("/msg/body/room"); int roomId = int.Parse(node.Attributes["id"].Value); //安全检测 if (!logicHasRoom(roomId)) { return; } if (!logicHasUserInRoom(session.RemoteEndPoint.ToString(), roomId)) { return; } //sr = server response string srAction = string.Empty; string contentXml = string.Empty; //尝试退出 logicLeaveRoom(session.RemoteEndPoint.ToString()); //回复 srAction = ServerAction.leaveRoomAndGoHallAutoMatch; // contentXml = "<rm id='" + roomId + "'/>"; Send(session, XmlInstruction.fengBao(srAction, contentXml) ); //log Log.WriteStrBySend(srAction, session.RemoteEndPoint.ToString()); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorLeaveRoomAndGoHallAutoMatch", exd.Message, exd.Source, exd.StackTrace); } }
static void appServer_NewSessionConnected(AppSession session) { session.Send("Welcome to SuperSocket Telnet Server"); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="doc"></param> /// <param name="item"></param> public void doorSetModuleVars(AppSession session, XmlDocument doc, SessionMessage item) { try { string strIpPort = session.RemoteEndPoint.ToString(); if (!logicHasUser(strIpPort)) { return; } XmlNode node = doc.SelectSingleNode("/msg/body"); XmlNode node2 = doc.SelectSingleNode("/msg/body/vars"); IUserModel user = logicGetUser(strIpPort); // RoomModelByToac roomToac = null; string game_result_xml_rc = string.Empty; string roomXml = string.Empty; // for (int i = 0; i < node2.ChildNodes.Count; i++) { string n = node2.ChildNodes[i].Attributes["n"].Value; string v = node2.ChildNodes[i].InnerText; //------------------------------------------------------- string[] setVarsStatus = {"",""}; // if (n == DdzLogic_Toac.name) { roomToac = new RoomModelByToac(user); setVarsStatus = roomToac.setVars(n, v); } else { throw new ArgumentException("can not find module name:" + n); } //------------------------------------------------------- if ("True" == setVarsStatus[0] || "true" == setVarsStatus[0]) { //---------------------------------------------------- if (n == DdzLogic_Toac.name) { //send 记录服务器,保存得分 game_result_xml_rc = roomToac.getMatchResultXmlByRc(); roomXml = roomToac.toXMLString(); // RCConnector.Write( XmlInstruction.DBfengBao(RCClientAction.updG, game_result_xml_rc) ); }else{ throw new ArgumentException("can not find module name:" + n); } // Log.WriteStrByTurn(SR.getRecordServer_displayName(), RCConnector.getRemoteEndPoint().ToString(), RCClientAction.updG); //---------------------------------------------------- // Send(session, XmlInstruction.fengBao(ServerAction.moduleVarsUpdate, roomXml) ); // Log.WriteStrBySend(ServerAction.moduleVarsUpdate, strIpPort); } else { Send(session, XmlInstruction.fengBao(ServerAction.moduleVarsUpdateKO, setVarsStatus[1]) ); // Log.WriteStrBySend(ServerAction.moduleVarsUpdateKO, strIpPort); } } } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "setModuleVars", exd.Message, exd.Source, exd.StackTrace); } }
private void ComplexClient_AcceptString(AppSession session, HslCommunication.NetHandle handle, string data) { // 接收到服务器发送过来的字符串数据时触发 }
public void doorPubAuMsg(AppSession session, XmlDocument doc, SessionMessage item) { try { string strIpPort = session.RemoteEndPoint.ToString(); //<msg t="sys"><body action="pubMsg" r="7"><txt><![CDATA[dffddf]]></txt></body></msg> XmlNode node = doc.SelectSingleNode("/msg/body"); string roomId = node.Attributes["r"].Value; //安全检测 if (!logicHasRoom(int.Parse(roomId)) ) { return; } if (!logicHasUserInRoom(session.RemoteEndPoint.ToString(), int.Parse(roomId)) ) { return; } XmlNode node2 = doc.SelectSingleNode("/msg/body/txt"); string saction = ServerAction.pubAuMsg; string contentXml = "<room id='" + roomId + "'>" + node2.OuterXml + "</room>"; netTurnRoom(strIpPort, int.Parse(roomId), saction, contentXml); //log Log.WriteStrByTurn(SR.Room_displayName, roomId, saction); } catch (Exception exd) { Log.WriteStrByException(CLASS_NAME, "doorSetRvars", exd.Message, exd.Source, exd.Message); } }
private void OnStreamEndRead(IAsyncResult result) { var stream = result.AsyncState as Stream; int thisRead = 0; try { thisRead = stream.EndRead(result); } catch (Exception e) { if (!IsIgnorableException(e)) { AppSession.Logger.Error(AppSession, e); } this.Close(CloseReason.SocketError); return; } if (thisRead <= 0) { this.Close(CloseReason.ClientClosing); return; } int offsetDelta; try { offsetDelta = AppSession.ProcessRequest(m_ReadBuffer, m_Offset, thisRead, true); } catch (Exception ex) { AppSession.Logger.Error(AppSession, "protocol error", ex); this.Close(CloseReason.ProtocolError); return; } try { if (offsetDelta != 0) { m_Offset += offsetDelta; m_Length -= offsetDelta; if (m_Length > AppSession.AppServer.Config.ReceiveBufferSize) { throw new Exception("Illigal offsetDelta"); } } m_Stream.BeginRead(m_ReadBuffer, m_Offset, m_Length, OnStreamEndRead, m_Stream); } catch (Exception exc) { if (!IsIgnorableException(exc)) { AppSession.Logger.Error(AppSession, exc); } this.Close(CloseReason.SocketError); return; } }
public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo) { session.Send(requestInfo.Body); Console.WriteLine("S:" + requestInfo.Body); }
public ActiveViewModel(AppSession session) { SupportsEvents = (session != null); Session = session ?? new AppSession(); }
public override void ExecuteCommand(AppSession session, StringPackageInfo requestInfo) { session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString()); }
// ReSharper disable once UnusedMember.Global protected TreeVm(AppSession session) : base(session) { RootNodes = new(); }
public Resource Post(AppSession session, string resourceName, Dictionary <string, string> parameters, Dictionary <string, string> formData) { return(null); }
public Resource Get(AppSession session, string name, Dictionary <string, string> parameters) { if (name.StartsWith("Events/")) { return(null); } var resourceName = GetAssemblyResourceName(name); var asmResource = _resources.Value .FirstOrDefault(res => string.Compare(res.Key, resourceName, true, CultureInfo.InvariantCulture) == 0); if (asmResource.Key == null) { var shortName = GetShortResourceName(AppAssembly, ".app.", resourceName); asmResource = _resources.Value .FirstOrDefault(res => string.Compare(res.Key, shortName, true, CultureInfo.InvariantCulture) == 0); } if (asmResource.Key == null) { _logger.LogInformation($"ResourceLoader({resourceName}): not found"); return(null); } var resourceExtension = Path.GetExtension(resourceName); var resourceType = ResourceType.GetByExtension(resourceExtension); if (resourceType == null) { _logger.LogInformation($"ResourceLoader({resourceName}): not found"); return(null); } using (var stream = asmResource.Value.Assembly.GetManifestResourceStream(asmResource.Value.FullName)) { if (stream != null) { if (resourceType.IsBinary) { // ReSharper disable once ConvertToUsingDeclaration using (var reader = new BinaryReader(stream)) { var data = reader.ReadBytes((int)stream.Length); _logger.LogDebug($"ResourceLoader({resourceName}): {asmResource.Value.FullName}"); return(new Resource(resourceName, "res://" + asmResource.Value.FullName, resourceType, data, Resource.Cache.Revalidate)); } } else { // ReSharper disable once ConvertToUsingDeclaration using (var reader = new StreamReader(stream)) { var text = reader.ReadToEnd(); _logger.LogDebug($"ResourceLoader({resourceName}): {asmResource.Value.FullName}"); text = text.Replace("{.min}", (session?.IsDebug ?? false) ? "" : ".min"); if (resourceName?.EndsWith("index.html", StringComparison.InvariantCultureIgnoreCase) ?? false) { text = UserContentLinks.InsertUserCssLinks(AppAssembly, "", text, session?.SubDomain ?? ""); text = UserContentLinks.InsertUserJsLinks(AppAssembly, "", text); } return(new Resource(resourceName, "res://" + asmResource.Value.FullName, resourceType, text, Resource.Cache.Revalidate)); } } } } _logger.LogInformation($"ResourceLoader({resourceName}): not found"); return(null); }