//------------------------------------------------------------------------- public override void init() { Init = false; CacheDesktopKey = "CacheDesktopData_" + Entity.Guid; DesktopConfigData = new Ps.DesktopConfigData(); DesktopConfigData.desktop_etguid = Entity.Guid; DesktopConfigData.seat_num = 6; DesktopConfigData.is_vip = false; DesktopConfigData.desktop_waitwhile_tm = 60; MapAllPlayer1 = new Dictionary <uint, Entity>(); MapAllPlayer = new Dictionary <string, Entity>(); byte index = 0; AllSeat = new SeatInfo[DesktopConfigData.seat_num]; foreach (var i in AllSeat) { SeatInfo seat_info = new SeatInfo(); seat_info.index = index; seat_info.et_player_rpcid = 0; seat_info.et_playermirror = null; AllSeat[index] = seat_info; index++; } DesktopInfo = new DesktopInfo(); DesktopInfo.desktop_etguid = Entity.Guid; DesktopInfo.seat_num = 6; DesktopInfo.desktop_tableid = 1; DesktopInfo.is_vip = false; DesktopInfo.list_seat_player = new List <DesktopPlayerInfo>(); DesktopInfo.all_player_num = 0; DesktopInfo.seat_player_num = 0; QueAoIEvent = new Queue <_tAoIEvent>(); QuePlayerId = new Queue <byte>(); MaxPlayerId = 0; for (int i = 0; i < 50; i++) { QuePlayerId.Enqueue(++MaxPlayerId); } TbDataRoom._eRoomType room_type = TbDataRoom._eRoomType.RT_Tenfold; bool fish_mustdie = true; bool is_single = false; float pumping_rate = 1f; string path_fishlord = Path.Combine(ServerPath.getPathMediaRoot(), "Fishing\\FishLord\\"); string path_route = Path.Combine(ServerPath.getPathMediaRoot(), "Fishing\\Route\\"); ILogicListener listener = new LogicListener(this); LogicScene = new CLogicScene(); LogicScene.create(1, 1.0f, is_single, fish_mustdie, listener, pumping_rate, _getRateList(room_type), CellApp.Instance.jsonCfg.json_packet_list, CellApp.Instance.jsonCfg.route_json_packet_list); }
private static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) { try { screenCapturer?.DisplaySettingsChanged(); Try.Catch(() => { dxgiDuplicator?.Dispose(); }); dxgiDuplicator = new DxgiOutputDuplicator(0, 0); desktopInfo = DxgiOutputDuplicator.GetDesktopInfo(); } catch (Exception ex) { Logger.Debug(ex); } }
/// <summary> /// This is the main entry point for the SHRD streamer. /// </summary> /// <param name="args"></param> public static void Run(string[] args) { string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; Globals.InitializeProgram(exePath, "Self Hosted Remote Desktop", true); PrivateAccessor.SetStaticFieldValue(typeof(Globals), "errorFilePath", Globals.WritableDirectoryBase + "SHRD_Streamer_Log.txt"); Logger.logType = LoggingMode.File; Logger.Info("SHRDStreamer Startup"); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; desktopInfo = DxgiOutputDuplicator.GetDesktopInfo(); streamerArgs = new StreamerArgs(args); thrMain = new Thread(mainThreadRunner); thrMain.Name = "Streamer Main"; thrMain.IsBackground = true; thrMain.Start(); thrDesktopCapture = new Thread(desktopCaptureThreadRunner); thrDesktopCapture.SetApartmentState(ApartmentState.MTA); thrDesktopCapture.Name = "Desktop Capture"; thrDesktopCapture.IsBackground = true; // thrDesktopCapture is started by thrMain after static_sm is set. if (streamerArgs.ServiceProcessId != null) { service_process = Process.GetProcessById(streamerArgs.ServiceProcessId.Value); thrMonitorService = new Thread(monitoringThreadRunner); thrMonitorService.Name = "Monitoring Service"; thrMonitorService.IsBackground = true; thrMonitorService.Start(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); //Application.Run(); }
//--------------------------------------------------------------------- // 初始化桌子信息 public Task s2sSetupDesktop(DesktopInfo desktop_info) { var tb_desktop = EbDataMgr.Instance.getData <TbDataDesktopInfo>(DesktopInfo.desktop_tableid); if (tb_desktop == null) { EbLog.Error("CellDesktop.s2sSetupDesktop() Error DesktopTableId=" + DesktopInfo.desktop_tableid); return(TaskDone.Done); } Init = true; DesktopInfo.seat_num = desktop_info.seat_num; DesktopInfo.desktop_tableid = desktop_info.desktop_tableid; DesktopInfo.is_vip = desktop_info.is_vip; DesktopInfo.all_player_num = desktop_info.all_player_num; DesktopInfo.seat_player_num = desktop_info.seat_player_num; DesktopInfo.list_seat_player.Clear(); DesktopConfigData.is_vip = DesktopInfo.is_vip; byte index = 0; AllSeat = new SeatInfo[DesktopConfigData.seat_num]; foreach (var i in AllSeat) { SeatInfo seat_info = new SeatInfo(); seat_info.index = index; seat_info.et_playermirror = null; AllSeat[index] = seat_info; index++; } string data = EbTool.jsonSerialize(DesktopInfo); DbClientCouchbase.Instance.asyncSave(CacheDesktopKey, data, TimeSpan.FromSeconds(15.0)); return(TaskDone.Done); }
public Display() { f.AutoFlush = true; _DesktopInfo = new DesktopInfo(); //_DesktopInfo.SwitchDesktop(Desktops.INPUT); _RunningAsService = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToLower().Contains(@"nt authority\system"); if (!_RunningAsService) { _RunningAsService = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToLower().Contains(@"nt-autorität\system"); } Windows.DfMirage.Display DfMirage = new DfMirage.Display(); f.WriteLine("Running as Service" + _RunningAsService + "DF:" + DfMirage.DoesMirrorDriverExist()); if (DfMirage.DoesMirrorDriverExist()) { Driver = DfMirage; } else { Driver = new Simple.Display(); } }
private void readSharedMemory(object args) { SharedMemoryStream mySm = (SharedMemoryStream)args; try { while (sm == mySm) { try { byte cmdByte = (byte)sm.ReadByte(); Command cmd = (Command)cmdByte; // Handle message from Streamer process. // TODO: Refactor the responses to use a generic wrapper class, e.g. // AsyncLoadingObject<FragmentedImage> newFrame = ...; // newFrame.Loaded(img); // if (newFrame.Wait(abortFlag, out ...)) // return ...; switch (cmd) { case Command.GetScreenCapture: FragmentedImage img = new FragmentedImage(sm); newFrame.Produce(img); break; case Command.GetDesktopInfo: DesktopInfo di = new DesktopInfo(sm); newDesktopInfo.Produce(di); break; case Command.Error_SyntaxError: case Command.Error_CommandCodeUnknown: case Command.Error_Unspecified: case Command.StartStreaming: case Command.StopStreaming: case Command.AcknowledgeFrame: case Command.ReproduceUserInput: case Command.SetStreamSettings: case Command.GetStreamSettings: default: Logger.Info("Received unexpected byte from Streamer process: " + cmd); // TODO: End the Streamer process now and start a new one, because we have just entered an undefined state. break; } } catch (ThreadAbortException) { throw; } catch (StreamDisconnectedException) { throw; } catch (Exception ex) { Logger.Debug(ex); } } } catch (ThreadAbortException) { } catch (StreamDisconnectedException) { Logger.Info("Read Shared Memory thread detected stream close (" + mySm.uniqueId + ")"); } catch (Exception ex) { Logger.Debug(ex); } finally { Try.Catch(() => { mySm?.Dispose(); }); RaiseOnCloseEvent(); } }
protected override void OnMessage(MessageEventArgs e) { if (!e.IsBinary) { CloseSocket(); return; } byte[] buf = e.RawData; if (buf.Length == 0) { CloseSocket(); return; } Command cmd = (Command)buf[0]; try { switch (cmd) { case Command.StartStreaming: if (buf.Length < 3) { SyntaxError(buf[0], buf); break; } StopStreaming(); Console.WriteLine(ID + " Command.StartStreaming " + (byte)Interlocked.Read(ref activeStreamNumber)); Send(new byte[] { buf[0], (byte)Interlocked.Read(ref activeStreamNumber) }); StartStreaming(buf); break; case Command.StopStreaming: Console.WriteLine(ID + " Command.StopStreaming"); StopStreaming(); break; case Command.AcknowledgeFrame: if (buf.Length < 2) { SyntaxError(buf[0], buf); break; } AcknowledgeFrame(buf[1]); break; case Command.ReproduceUserInput: if (buf.Length < 2) { SyntaxError(buf[0], buf); break; } InputType inputType = (InputType)buf[1]; if (inputType == InputType.KeyDown || inputType == InputType.KeyUp) { if (buf.Length < 10) { SyntaxError(buf[0], buf, inputType); break; } int keyCode = ByteUtil.ReadInt32(buf, 2); ModifierKeys modifiers = (ModifierKeys)ByteUtil.ReadUInt32(buf, 6); streamerController.DoKeyboardInput(keyCode, modifiers, inputType == InputType.KeyUp); } else if (inputType == InputType.MouseMove) { if (buf.Length < 10) { SyntaxError(buf[0], buf, inputType); break; } float x = ByteUtil.ReadFloat(buf, 2); float y = ByteUtil.ReadFloat(buf, 6); streamerController.DoMouseMove(x, y); } else if (inputType == InputType.MouseButtonDown || inputType == InputType.MouseButtonUp) { if (buf.Length < 3) { SyntaxError(buf[0], buf, inputType); break; } MouseButton button = (MouseButton)buf[2]; streamerController.DoMouseButton(button, inputType == InputType.MouseButtonUp); } else if (inputType == InputType.MouseWheel) { if (buf.Length < 6) { SyntaxError(buf[0], buf, inputType); break; } short deltaX = ByteUtil.ReadInt16(buf, 2); short deltaY = ByteUtil.ReadInt16(buf, 4); streamerController.DoMouseWheel(deltaX, deltaY); } break; case Command.GetDesktopInfo: DesktopInfo desktopInfo = streamerController.GetDesktopInfo(); using (MemoryDataStream mds = new MemoryDataStream()) { desktopInfo.WriteToDataStream(mds); Send(mds.ToArray()); } break; case Command.SetStreamSettings: if (buf.Length < 5) { SyntaxError(buf[0], buf); break; } imgFlags = (ImgFlags)buf[1]; jpegQuality = BPMath.Clamp <byte>(buf[2], 1, 100); maxFPS = BPMath.Clamp <byte>(buf[3], 1, byte.MaxValue); maxUnacknowledgedFrames = BPMath.Clamp <byte>(buf[4], 1, byte.MaxValue); break; case Command.GetStreamSettings: byte[] response = new byte[4]; response[0] = buf[0]; response[1] = (byte)imgFlags; response[2] = jpegQuality; response[3] = maxFPS; Send(response); break; case Command.KeepAlive: break; default: // CloseSocket(); Send(new byte[] { (byte)Command.Error_CommandCodeUnknown }); break; } } catch (ThreadAbortException) { throw; } catch (Exception ex) { Logger.Debug(ex, "WebSocketServer"); } }
//--------------------------------------------------------------------- // 立即玩 public async Task enterDesktopPlayNow() { if (IsEntering) { EbLog.Note("CellPlayerDesktop.enterDesktopPlayNow() 错误:正在进入中"); return; } IsEntering = true; if (!string.IsNullOrEmpty(DesktopEtGuid)) { await leaveDesktop(); } DesktopRequestPlayerEnter request_enter; request_enter.desktop_etguid = ""; request_enter.seat_index = 255; request_enter.player_clip = 0; request_enter.player_gold = CoActor.Def.PropGold.get(); request_enter.is_vip = CoActor.Def.mPropIsVIP.get(); var grain = Entity.getUserData <GrainCellPlayer>(); var grain_desktopservice = grain.GF.GetGrain <ICellDesktopService>(0); DesktopInfo desktop_info = await grain_desktopservice.searchDesktopAuto(request_enter); if (string.IsNullOrEmpty(desktop_info.desktop_etguid)) { EbLog.Note("CellPlayerDesktop.enterDesktopPlayNow() 获取桌子信息出错"); } else { EbLog.Note("CellPlayerDesktop.enterDesktopPlayNow() 获取桌子信息成功"); } // Step1:监听桌子广播 await _createDesktopStreamConsumer(desktop_info.desktop_etguid); // 自动下注 int bet_chip = 2000; int left_chip = CoActor.Def.PropGold.get(); if (left_chip < bet_chip) { bet_chip = left_chip; } left_chip -= bet_chip; CoPlayer.CoActor.Def.PropGold.set(left_chip); // Step2:进入桌子并获取桌子初始化信息 var grain_desktop = grain.GF.GetGrain <ICellDesktop>(new Guid(desktop_info.desktop_etguid)); DesktopData desktop_data = await grain_desktop.s2sPlayerEnter(request_enter, CoPlayer.exportEtPlayerMirror()); IsEntering = false; DesktopEtGuid = desktop_data.desktop_cfg_data.desktop_etguid; DesktopNotify desktop_notify; desktop_notify.id = DesktopNotifyId.DesktopInit; desktop_notify.data = EbTool.protobufSerialize <DesktopData>(desktop_data); MethodData notify_data = new MethodData(); notify_data.method_id = MethodType.s2cPlayerDesktopNotify; notify_data.param1 = EbTool.protobufSerialize <DesktopNotify>(desktop_notify); var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid)); grain_player.s2sNotify(notify_data); }