public static NamedPipeStream Create(string pipeName, ServerMode mode, bool isAsync)
        {
            NamedPipeStream stream;
            SafePipeHandle handle = Windows.CreateNamedPipe(@"\\.\pipe\" + pipeName, (uint) (mode | (isAsync ? ((ServerMode) 0x40000000) : ((ServerMode) 0))), 0, 0xff, 0, 0x400, uint.MaxValue, IntPtr.Zero);
            if (handle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(HRESULT.HRESULT_FROM_WIN32(Marshal.GetLastWin32Error()));
            }
            FileAccess read = 0;
            switch (mode)
            {
                case ServerMode.Inbound:
                    read = FileAccess.Read;
                    break;

                case ServerMode.Outbound:
                    read = FileAccess.Write;
                    break;

                case ServerMode.Bidirectional:
                    read = FileAccess.ReadWrite;
                    break;
            }
            return new NamedPipeStream(new SafeFileHandle(handle.DangerousGetHandle(), true), read, isAsync) { PipeHandle = handle, FPeerType = PeerType.Server, AsyncListen = new ListenHandler(stream.Listen) };
        }
Example #2
0
 private void Start()
 {
     m_isConnected = false;
     m_isLoggedIn  = false;
     m_isInRoom    = false;
     m_serviceSet  = false;
     m_qTime       = 20;
     smartFox      = null;
     if (true)
     {
         mServerMode = ServerMode.director;
     }
     else
     {
         serverName  = CN_INTERNAL;
         mServerMode = ServerMode.single;
     }
     if (mServerMode == ServerMode.single)
     {
         InitSmartfox();
     }
     else
     {
         AskDirector();
     }
 }
		public override void LaunchLocalServer(Process process, ServerMode mode)
		{
			if (this._lobby.State != LobbyState.Inactive)
			{
				this._lobby.Leave();
			}
			ProcessStartInfo expr_1E = process.StartInfo;
			expr_1E.Arguments = expr_1E.Arguments + " -steam -localsteamid " + SteamUser.GetSteamID().m_SteamID;
			if (mode.HasFlag(ServerMode.Lobby))
			{
				this._hasLocalHost = true;
				if (mode.HasFlag(ServerMode.FriendsCanJoin))
				{
					ProcessStartInfo expr_78 = process.StartInfo;
					expr_78.Arguments += " -lobby friends";
				}
				else
				{
					ProcessStartInfo expr_95 = process.StartInfo;
					expr_95.Arguments += " -lobby private";
				}
				if (mode.HasFlag(ServerMode.FriendsOfFriends))
				{
					ProcessStartInfo expr_C3 = process.StartInfo;
					expr_C3.Arguments += " -friendsoffriends";
				}
			}
			SteamFriends.SetRichPresence("status", "Playing online.");
			Netplay.OnDisconnect += new Action(this.OnDisconnect);
			process.Start();
		}
        public override void LaunchLocalServer(Process process, ServerMode mode)
        {
            if (_lobby.State != 0)
            {
                _lobby.Leave();
            }
            ProcessStartInfo startInfo = process.StartInfo;

            startInfo.Arguments = startInfo.Arguments + " -steam -localsteamid " + SteamUser.GetSteamID().m_SteamID;
            if (mode.HasFlag(ServerMode.Lobby))
            {
                _hasLocalHost = true;
                if (mode.HasFlag(ServerMode.FriendsCanJoin))
                {
                    process.StartInfo.Arguments += " -lobby friends";
                }
                else
                {
                    process.StartInfo.Arguments += " -lobby private";
                }
                if (mode.HasFlag(ServerMode.FriendsOfFriends))
                {
                    process.StartInfo.Arguments += " -friendsoffriends";
                }
            }
            SteamFriends.SetRichPresence("status", "Playing online.");
            Netplay.OnDisconnect += OnDisconnect;
            process.Start();
        }
Example #5
0
        protected override void OnSettingsLoaded(object sender, SettingsLoadedEventArgs e)
        {
            ServerMode      mode = (ServerMode)this["Mode"];
            ServerArguments args = new ServerArguments();

            //get fix mode
            bool fixMode = ((mode & ServerMode.Fix) != 0) || args.IsFix;

            //assert fix mode
            if (fixMode)
            {
                mode |= ServerMode.Fix;
            }

            //adjust mode
            if (fixMode)
            {
                //switch off network and wcf
                mode |= ServerMode.NoNetwork;
                mode |= ServerMode.NoWCF;

                //switch on database
                if ((mode & ServerMode.NoDatabase) != 0)
                {
                    mode ^= ServerMode.NoDatabase;
                }

                //update mode
                this["Mode"] = mode;
            }

            base.OnSettingsLoaded(sender, e);
        }
Example #6
0
        public override void Initialize()
        {
            base.Initialize();
            _reader.SetReadEvent(OnPacketRead);
            _p2pSessionRequest = Callback <P2PSessionRequest_t> .Create((DispatchDelegate <P2PSessionRequest_t>) OnP2PSessionRequest);

            if (Program.LaunchParameters.ContainsKey("-lobby"))
            {
                _mode |= ServerMode.Lobby;
                string a = Program.LaunchParameters["-lobby"];
                if (!(a == "private"))
                {
                    if (a == "friends")
                    {
                        _mode |= ServerMode.FriendsCanJoin;
                        _lobby.Create(inviteOnly: false, OnLobbyCreated);
                    }
                    else
                    {
                        Console.WriteLine(Language.GetTextValue("Error.InvalidLobbyFlag", "private", "friends"));
                    }
                }
                else
                {
                    _lobby.Create(inviteOnly: true, OnLobbyCreated);
                }
            }
            if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
            {
                _mode |= ServerMode.FriendsOfFriends;
            }
        }
Example #7
0
        public void ServiceInfo()
        {
            Service    service = Connect();
            ServerInfo info    = service.Server.GetInfoAsync().Result;

            bool dummyBool;
            int  dummyInt;

            string[] dummyStrings;
            string   dummyString;

            dummyInt    = info.Build;
            dummyString = info.CpuArchitecture;
            Guid guid = info.Guid;
            IReadOnlyList <string> licents     = info.LicenseKeys;
            IReadOnlyList <string> licentLabel = info.LicenseLabels;

            dummyString = info.LicenseSignature;
            LicenseState state = info.LicenseState;
            Guid         guid2 = info.MasterGuid;
            ServerMode   mode  = info.Mode;

            dummyString = info.OSBuild;
            dummyString = info.OSName;
            dummyString = info.OSVersion;
            dummyString = info.ServerName;
            Version version = info.Version;

            dummyBool = info.IsFree;
            dummyBool = info.IsRealtimeSearchEnabled;
            dummyBool = info.IsTrial;
        }
		public override void Initialize()
		{
			base.Initialize();
			this._reader.SetReadEvent(new SteamP2PReader.OnReadEvent(this.OnPacketRead));
			this._p2pSessionRequest = Callback<P2PSessionRequest_t>.Create(new Callback<P2PSessionRequest_t>.DispatchDelegate(this.OnP2PSessionRequest));
			if (Program.LaunchParameters.ContainsKey("-lobby"))
			{
				this._mode |= ServerMode.Lobby;
				string a;
				if ((a = Program.LaunchParameters["-lobby"]) != null)
				{
					if (a == "private")
					{
						this._lobby.Create(true, new CallResult<LobbyCreated_t>.APIDispatchDelegate(this.OnLobbyCreated));
						goto IL_D3;
					}
					if (a == "friends")
					{
						this._mode |= ServerMode.FriendsCanJoin;
						this._lobby.Create(false, new CallResult<LobbyCreated_t>.APIDispatchDelegate(this.OnLobbyCreated));
						goto IL_D3;
					}
				}
				Console.WriteLine("-lobby flag used without \"private\" or \"friends\". Ignoring it.");
			}
			IL_D3:
			if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
			{
				this._mode |= ServerMode.FriendsOfFriends;
			}
		}
        public override void LaunchLocalServer(Process process, ServerMode mode)
        {
            if (this._lobby.State != LobbyState.Inactive)
            {
                this._lobby.Leave();
            }
            ProcessStartInfo startInfo = process.StartInfo;
            string           str       = startInfo.Arguments + " -steam -localsteamid " + (object)(ulong)SteamUser.GetSteamID().m_SteamID;

            startInfo.Arguments = str;
            if (mode.HasFlag((Enum)ServerMode.Lobby))
            {
                this._hasLocalHost = true;
                if (mode.HasFlag((Enum)ServerMode.FriendsCanJoin))
                {
                    process.StartInfo.Arguments += " -lobby friends";
                }
                else
                {
                    process.StartInfo.Arguments += " -lobby private";
                }
                if (mode.HasFlag((Enum)ServerMode.FriendsOfFriends))
                {
                    process.StartInfo.Arguments += " -friendsoffriends";
                }
            }
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Netplay.OnDisconnect += new Action(this.OnDisconnect);
            process.Start();
        }
        public override void Initialize()
        {
            base.Initialize();
            this._reader.SetReadEvent(new SteamP2PReader.OnReadEvent(this.OnPacketRead));
            // ISSUE: method pointer
            this._p2pSessionRequest = Callback <P2PSessionRequest_t> .Create(new Callback <P2PSessionRequest_t> .DispatchDelegate((object)this, __methodptr(OnP2PSessionRequest)));

            if (Program.LaunchParameters.ContainsKey("-lobby"))
            {
                this._mode |= ServerMode.Lobby;
                switch (Program.LaunchParameters["-lobby"])
                {
                case "private":
                    // ISSUE: method pointer
                    this._lobby.Create(true, new CallResult <LobbyCreated_t> .APIDispatchDelegate((object)this, __methodptr(OnLobbyCreated)));
                    break;

                case "friends":
                    this._mode |= ServerMode.FriendsCanJoin;
                    // ISSUE: method pointer
                    this._lobby.Create(false, new CallResult <LobbyCreated_t> .APIDispatchDelegate((object)this, __methodptr(OnLobbyCreated)));
                    break;

                default:
                    Console.WriteLine(Language.GetTextValue("Error.InvalidLobbyFlag", (object)"private", (object)"friends"));
                    break;
                }
            }
            if (!Program.LaunchParameters.ContainsKey("-friendsoffriends"))
            {
                return;
            }
            this._mode |= ServerMode.FriendsOfFriends;
        }
Example #11
0
        public ServerStartResult Start(IPEndPoint serverEndpoint, ushort steamPort, ServerMode serverMode, string versionString, bool gameSocketShare)
        {
            byte[] verPtr_12_cp_0 = Encoding.UTF8.GetBytes(versionString);
            //int verPtr_12_cp_1 = 0;
            if (!gameSocketShare && !this.TestSocket(serverEndpoint))
            {
                return(ServerStartResult.PortAlreadyUsed);
            }
            uint arg_4E_0 = serverEndpoint.Address.ToIPv4NetworkOrder();
            int  serverEndpoint2;

            if (gameSocketShare)
            {
                serverEndpoint2 = 65535;
            }
            else
            {
                serverEndpoint2 = serverEndpoint.Port + 1;
            }

            //if (<Module>.SteamGameServer_Init(arg_4E_0, steamPort, (ushort)serverEndpoint.Port, (ushort)serverEndpoint2, (EServerMode)serverMode, ref verPtr_12_cp_0[verPtr_12_cp_1]) != null)
            //{
            //    if (gameSocketShare)
            //    {
            //        this.m_masterServerThreadExit = false;
            //        Thread this2 = new Thread(new ParameterizedThreadStart(this.MasterServerUpdaterThread));
            //        this.m_masterServerUpdaterThread = this2;
            //        this2.IsBackground = true;
            //        this.m_masterServerUpdaterThread.Start(serverEndpoint);
            //    }
            //    Peer2Peer.NetworkingEnabled = true;
            //    return ServerStartResult.OK;
            //}
            return(ServerStartResult.UnknownError);
        }
Example #12
0
        public override void LaunchLocalServer(Process process, ServerMode mode)
        {
            //IL_0039: Unknown result type (might be due to invalid IL or missing references)
            WeGameHelper.WriteDebugString("LaunchLocalServer");
            if (_lobby.State != 0)
            {
                _lobby.Leave();
            }
            ProcessStartInfo startInfo = process.StartInfo;

            startInfo.Arguments = startInfo.Arguments + " -steam -localsteamid " + SteamUser.GetSteamID().m_SteamID;
            if (mode.HasFlag(ServerMode.Lobby))
            {
                _hasLocalHost = true;
                if (mode.HasFlag(ServerMode.FriendsCanJoin))
                {
                    process.StartInfo.Arguments += " -lobby friends";
                }
                else
                {
                    process.StartInfo.Arguments += " -lobby private";
                }
                if (mode.HasFlag(ServerMode.FriendsOfFriends))
                {
                    process.StartInfo.Arguments += " -friendsoffriends";
                }
            }
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Netplay.OnDisconnect += OnDisconnect;
            process.Start();
        }
        public override void Initialize()
        {
            base.Initialize();
            _reader.SetReadEvent(OnPacketRead);
            _p2pSessionRequest = Callback <P2PSessionRequest_t> .Create(OnP2PSessionRequest);

            if (Program.LaunchParameters.ContainsKey("-lobby"))
            {
                _mode |= ServerMode.Lobby;
                switch (Program.LaunchParameters["-lobby"])
                {
                case "private":
                    _lobby.Create(true, OnLobbyCreated);
                    break;

                case "friends":
                    _mode |= ServerMode.FriendsCanJoin;
                    _lobby.Create(false, OnLobbyCreated);
                    break;

                default:
                    Console.WriteLine("-lobby flag used without \"private\" or \"friends\". Ignoring it.");
                    break;
                }
            }
            if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
            {
                _mode |= ServerMode.FriendsOfFriends;
            }
        }
Example #14
0
 public WorkerConfig()
 {
     ManagerUrl = "";
     Mode = ServerMode.None;
     MaxThreads = 2*Environment.ProcessorCount;
     Hostname = "127.0.0.1";
     Port = 0;
 }
 public static SocketServerBase CreateSocketServer(ServerMode serverMode)
 {
     if (serverMode == ServerMode.TCP)
         return new TcpAsyncSocketServer();
     else if (serverMode == ServerMode.UDP)
         return new UdpSocketAsyncServer();
     else
         return null;
 }
Example #16
0
        public void Close()
        {
            if (mode >= ServerMode.WaitClose)
            {
                return;
            }

            mode = ServerMode.WaitClose;
            sysSocket.Close();
        }
Example #17
0
        public JobServiceProxy(ServerConfiguration configuration)
        {
            // TODO:config.
            _caCertificate = new X509Certificate2().LoadFromPemFile("ca.crt");

            _serverMode = configuration.Mode;
            _uri = new UriBuilder("net.tcp", configuration.Address, configuration.Port, "master").Uri;
            _masterCommonName = configuration.CommonName;

            _certificatePemFile = configuration.CertificatePemFile;
        }
 public static ISocketClient CreateSocketServer(ServerMode serverMode)
 {
     if (serverMode == ServerMode.TCP)
         return new TcpSocketClient();
     else if (serverMode == ServerMode.UDP)
         return new UdpSocketClient();
     else if (serverMode == ServerMode.AtonUDP)
         return new UdpAtonSocketClient();
     else
         return null;
 }
Example #19
0
 private Mode ToMode(ServerMode mode)
 {
     if (ServerMode.BIG == mode)
     {
         return(Mode.大数据包模式);
     }
     if (ServerMode.SMALL == mode)
     {
         return(Mode.小数据包模式);
     }
     return(Mode.全透明模式);
 }
Example #20
0
 public ImagesController(ImageRepo repo)
 {
     _repo = repo;
     if (Environment.GetCommandLineArgs().Length > 1)
     {
         _mode = Environment.GetCommandLineArgs()[1] == "nb" ? ServerMode.NonBlocking : ServerMode.Blocking;
         System.Console.WriteLine(Environment.GetCommandLineArgs()[1]);
     }
     else
     {
         _mode = ServerMode.Blocking;
     }
 }
Example #21
0
        private void button6_Click(object sender, EventArgs e)
        {
            ServerMode sm = ServerMode.SM_CLIENT;

            switch (comboBox5.SelectedIndex)
            {
            case 0:
                sm = ServerMode.SM_CLIENT;
                break;

            case 1:
                sm = ServerMode.SM_SERVER_SINGLE_SESSION;
                break;

            case 2:
                sm = ServerMode.SM_SERVER_MULTISESSION;
                break;
            }

            int  port       = 0;
            bool result     = int.TryParse(textBox5.Text, out port);
            int  initResult = 0;

            if (result)
            {
                //string ip = "";
                if (sm == ServerMode.SM_SERVER_MULTISESSION || sm == ServerMode.SM_SERVER_SINGLE_SESSION)
                {
                    initResult = init(sm, "127.0.0.1", port, NewEventDelegate, NewIntegerValueDelegate, NewDoubleValueDelegate, NewStringValueDelegate, (IntPtr)0);
                }
                else
                {
                    if (textBox1.Text.Length > 0)
                    {
                        initResult = init(ServerMode.SM_CLIENT, textBox1.Text, port, NewEventDelegate, NewIntegerValueDelegate, NewDoubleValueDelegate, NewStringValueDelegate, (IntPtr)0);
                    }
                }
            }

            if (initResult > 0)
            {
                panel4.Enabled    = false;
                panel1.Enabled    = true;
                panel3.Enabled    = true;
                button6.Enabled   = false;
                comboBox5.Enabled = false;
                button7.Enabled   = true;
                timer1.Enabled    = true;
            }
        }
Example #22
0
        /// <summary>
        /// Create a named pipe instance.
        /// </summary>
        /// <param name="pipeName">Local name (the part after \\.\pipe\)</param>
        public static NamedPipeStream Create(string pipeName, ServerMode mode, FileSecurity fileSec)
        {
            SECURITY_ATTRIBUTES pipeSecurity = new SECURITY_ATTRIBUTES();

            pipeSecurity.nLength = Marshal.SizeOf(pipeSecurity);
            byte[] src  = fileSec.GetSecurityDescriptorBinaryForm();
            IntPtr dest = Marshal.AllocHGlobal(src.Length);

            Marshal.Copy(src, 0, dest, src.Length);
            pipeSecurity.lpSecurityDescriptor = dest;
            IntPtr pipeSecPtr = Marshal.AllocHGlobal(pipeSecurity.nLength);

            Marshal.StructureToPtr(pipeSecurity, pipeSecPtr, true);

            IntPtr handle = IntPtr.Zero;
            string name   = @"\\.\pipe\" + pipeName;

            handle = CreateNamedPipe(
                name,
                (uint)mode, PIPE_TYPE_MESSAGE | PIPE_WAIT,
                PIPE_UNLIMITED_INSTANCES,
                0,    // outBuffer,
                1024, // inBuffer,
                NMPWAIT_WAIT_FOREVER,
                pipeSecPtr);
            if (handle == INVALID_HANDLE_VALUE)
            {
                throw new Win32Exception("Error creating named pipe " + name + " . Internal error: " + Marshal.GetLastWin32Error().ToString());
            }

            // Set members persistently...
            NamedPipeStream self = new NamedPipeStream();

            self._handle = handle;
            switch (mode)
            {
            case ServerMode.InboundOnly:
                self._mode = FileAccess.Read;
                break;

            case ServerMode.OutboundOnly:
                self._mode = FileAccess.Write;
                break;

            case ServerMode.Bidirectional:
                self._mode = FileAccess.ReadWrite;
                break;
            }
            return(self);
        }
Example #23
0
        private static HttpWebRequest CreateWebRequest(string requestUrl, ServerMode serverMode = ServerMode.WebAPI)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUrl);

            if (serverMode == ServerMode.Soap)
            {
                webRequest.ContentType = "text/xml; charset =\"utf-8\"";
                webRequest.Accept      = "text/xml";
            }
            else
            {
                webRequest.ContentType = "application/x-www-form-urlencoded";
            }
            webRequest.Method = "POST";
            return(webRequest);
        }
Example #24
0
        public void BeginAccept()
        {
            if (mode >= ServerMode.WaitClose)
            {
                throw new ObjectDisposedException("Server is closed.");
            }

            acceptController.BeginAccept();

            if (mode == ServerMode.Running)
            {
                return;
            }

            mode = ServerMode.Running;
            sysSocket.BeginAccept(AcceptCallback, null);
        }
Example #25
0
 private void buttonStartServer_Click(object sender, EventArgs e)
 {
     try
     {
         ServerAPI.Start(config.IRExePath, "-server");
         serverStatus = ServerMode.Running;  //Required to fix Auto-restart script.  If you stop server manually this is always in the stopped state and breaks it entirely.
     }
     #pragma warning disable 0168
     catch (ProcessAlreadyStartedException ex)
     #pragma warning restore 0168
     {
         MessageBox.Show("Interstellar Rift is already running properly", "Launch error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     #pragma warning disable 0168
     catch (IRRunningDetachedException ex)
     #pragma warning restore 0168
     {
         MessageBox.Show("Interstellar Rift is already running and not monitored by ISRSM.  Please terminate it and start the server from here.", "Launch error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #26
0
        public DHCP(IPEndPoint socket, int port, ServerMode mode = ServerMode.KnownOnly)
        {
            this.ntlmkey = new byte[24];
            requestid = Settings.RequestID;

            this.BINLsocket = new BINLSocket(new IPEndPoint(IPAddress.Any, port));
            this.BINLsocket.Type = SocketType.BINL;
            this.BINLsocket.DataReceived += this.DataReceived;
            this.BINLsocket.DataSend += this.DataSend;

            if (Settings.EnableDHCP)
            {
                this.DHCPsocket = new DHCPSocket(new IPEndPoint(IPAddress.Any, 67), true);
                this.DHCPsocket.Type = SocketType.DHCP;
                this.DHCPsocket.DataReceived += this.DataReceived;
                this.DHCPsocket.DataSend += this.DataSend;

                if (Settings.AdvertPXEServerList)
                    Functions.ReadServerList(Settings.ServersFile, ref Servers);
            }
        }
Example #27
0
        private void buttonStopServer_Click(object sender, EventArgs e)
        {
            ExitTimeForm etfDialog = new ExitTimeForm();

            etfDialog.Minutes        = config.LastShutdownTime;
            etfDialog.RestartEnabled = config.RestartServer;

            if (etfDialog.ShowDialog(this) == DialogResult.OK)
            {
                if (!etfDialog.RestartEnabled)
                {
                    serverStatus = ServerMode.Stopped;
                }

                ServerAPI.ExitTimer(etfDialog.Minutes * 60, "Server is Shutting Down in " + etfDialog.Minutes + " minutes!!");

                config.LastShutdownTime = etfDialog.Minutes;
                config.RestartServer    = etfDialog.RestartEnabled;
                config.SaveConfig();
            }
            etfDialog.Dispose();
        }
Example #28
0
        public override void LaunchLocalServer(Process process, ServerMode mode)
        {
            //IL_00ec: Unknown result type (might be due to invalid IL or missing references)
            if (_lobby.State != 0)
            {
                _lobby.Leave();
            }
            LazyCreateWeGameMsgServer();
            ProcessStartInfo startInfo = process.StartInfo;

            startInfo.Arguments = startInfo.Arguments + " -wegame -localwegameid " + ((RailComparableID)GetLocalPeer()).id_;
            if (mode.HasFlag(ServerMode.Lobby))
            {
                _hasLocalHost = true;
                if (mode.HasFlag(ServerMode.FriendsCanJoin))
                {
                    process.StartInfo.Arguments += " -lobby friends";
                }
                else
                {
                    process.StartInfo.Arguments += " -lobby private";
                }
                if (mode.HasFlag(ServerMode.FriendsOfFriends))
                {
                    process.StartInfo.Arguments += " -friendsoffriends";
                }
            }
            string str = default(string);

            rail_api.RailFactory().RailUtils().GetLaunchAppParameters((EnumRailLaunchAppType)2, ref str);
            ProcessStartInfo startInfo2 = process.StartInfo;

            startInfo2.Arguments = startInfo2.Arguments + " " + str;
            WeGameHelper.WriteDebugString("LaunchLocalServer,cmd_line:" + process.StartInfo.Arguments);
            AsyncSetMyMetaData("status", Language.GetTextValue("Social.StatusInGame"));
            Netplay.OnDisconnect += OnDisconnect;
            process.Start();
        }
Example #29
0
        /// <summary>
        /// Create a named pipe instance.
        /// </summary>
        /// <param name="pipeName">Local name (the part after \\.\pipe\)</param>
        public static NamedPipeStream Create(string pipeName, ServerMode mode)
        {
            IntPtr handle = IntPtr.Zero;
            string name   = @"\\.\pipe\" + pipeName;

            handle = CreateNamedPipe(
                name,
                (uint)mode,
                PIPE_TYPE_BYTE | PIPE_WAIT,
                PIPE_UNLIMITED_INSTANCES,
                0,    // outBuffer,
                1024, // inBuffer,             NMPWAIT_WAIT_FOREVER,
                IntPtr.Zero);
            if (handle.ToInt32() == INVALID_HANDLE_VALUE)
            {
                throw new Win32Exception("Error creating named pipe " + name + " . Internal error: " + Marshal.GetLastWin32Error().ToString());
            }
            // Set members persistently...
            NamedPipeStream self = new NamedPipeStream();

            self._handle = handle;
            switch (mode)
            {
            case ServerMode.InboundOnly:
                self._mode = FileAccess.Read;
                break;

            case ServerMode.OutboundOnly:
                self._mode = FileAccess.Write;
                break;

            case ServerMode.Bidirectional:
                self._mode = FileAccess.ReadWrite;
                break;
            }
            return(self);
        }
 public override void Initialize()
 {
     base.Initialize();
     _mode |= ServerMode.Lobby;
     RegisterRailEvent();
     _reader.SetReadEvent(OnPacketRead);
     if (Program.LaunchParameters.ContainsKey("-lobby"))
     {
         _mode |= ServerMode.Lobby;
         string a = Program.LaunchParameters["-lobby"];
         if (!(a == "private"))
         {
             if (a == "friends")
             {
                 _mode |= ServerMode.FriendsCanJoin;
                 _lobby.Create(inviteOnly: false);
             }
             else
             {
                 Console.WriteLine(Language.GetTextValue("Error.InvalidLobbyFlag", "private", "friends"));
             }
         }
         else
         {
             _lobby.Create(inviteOnly: true);
         }
     }
     if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
     {
         _mode |= ServerMode.FriendsOfFriends;
     }
     _client.Init("WeGame.Terraria.Message.Client", "WeGame.Terraria.Message.Server");
     _client.OnConnected     += OnConnected;
     _client.OnMessage       += OnWegameMessage;
     CoreSocialModule.OnTick += _client.Tick;
     _client.Start();
 }
Example #31
0
 public override void Initialize()
 {
     base.Initialize();
     this._mode |= ServerMode.Lobby;
     this.RegisterRailEvent();
     this._reader.SetReadEvent(new WeGameP2PReader.OnReadEvent(this.OnPacketRead));
     if (Program.LaunchParameters.ContainsKey("-lobby"))
     {
         this._mode |= ServerMode.Lobby;
         string launchParameter = Program.LaunchParameters["-lobby"];
         if (!(launchParameter == "private"))
         {
             if (launchParameter == "friends")
             {
                 this._mode |= ServerMode.FriendsCanJoin;
                 this._lobby.Create(false);
             }
             else
             {
                 Console.WriteLine(Language.GetTextValue("Error.InvalidLobbyFlag", (object)"private", (object)"friends"));
             }
         }
         else
         {
             this._lobby.Create(true);
         }
     }
     if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
     {
         this._mode |= ServerMode.FriendsOfFriends;
     }
     this._client.Init("WeGame.Terraria.Message.Client", "WeGame.Terraria.Message.Server");
     this._client.OnConnected += new Action(this.OnConnected);
     this._client.OnMessage   += new Action <IPCMessage>(this.OnWegameMessage);
     CoreSocialModule.OnTick  += new Action(this._client.Tick);
     this._client.Start();
 }
Example #32
0
        public override void LaunchLocalServer(Process process, ServerMode mode)
        {
            if (this._lobby.State != LobbyState.Inactive)
            {
                this._lobby.Leave();
            }
            this.LazyCreateWeGameMsgServer();
            ProcessStartInfo startInfo1 = process.StartInfo;

            startInfo1.Arguments = startInfo1.Arguments + " -wegame -localwegameid " + (object)(ulong)((RailComparableID)this.GetLocalPeer()).id_;
            if (mode.HasFlag((Enum)ServerMode.Lobby))
            {
                this._hasLocalHost = true;
                if (mode.HasFlag((Enum)ServerMode.FriendsCanJoin))
                {
                    process.StartInfo.Arguments += " -lobby friends";
                }
                else
                {
                    process.StartInfo.Arguments += " -lobby private";
                }
                if (mode.HasFlag((Enum)ServerMode.FriendsOfFriends))
                {
                    process.StartInfo.Arguments += " -friendsoffriends";
                }
            }
            string str;

            rail_api.RailFactory().RailUtils().GetLaunchAppParameters((EnumRailLaunchAppType)2, ref str);
            ProcessStartInfo startInfo2 = process.StartInfo;

            startInfo2.Arguments = startInfo2.Arguments + " " + str;
            WeGameHelper.WriteDebugString("LaunchLocalServer,cmd_line:" + process.StartInfo.Arguments);
            this.AsyncSetMyMetaData("status", Language.GetTextValue("Social.StatusInGame"));
            Netplay.OnDisconnect += new Action(this.OnDisconnect);
            process.Start();
        }
Example #33
0
        internal void Run(ServerMode mode)
        {
            Socket socket = new Socket(
                AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Bind(new IPEndPoint(IPAddress.Any, Constants.PORT));

            socket.Listen(10);

            while (true)
            {
                Socket client = socket.Accept();
                try
                {
                    switch (mode)
                    {
                    case ServerMode.Memory:
                        MemorySend(client);
                        break;

                    case ServerMode.ReadSend:
                        ReadSend(client);
                        break;

                    case ServerMode.TransmitFile:
                        TransmitFile(client);
                        break;
                    }
                }
                finally
                {
                    client.Shutdown(SocketShutdown.Both);
                    client.Close();
                }
            }
        }
Example #34
0
        internal void Run(ServerMode mode)
        {
            Socket socket = new Socket(
                AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Bind(new IPEndPoint(IPAddress.Any, Constants.PORT));

            socket.Listen(10);

            while (true)
            {
                Socket client = socket.Accept();
                try
                {
                    switch (mode)
                    {
                        case ServerMode.Memory:
                            MemorySend(client);
                            break;

                        case ServerMode.ReadSend:
                            ReadSend(client);
                            break;

                        case ServerMode.TransmitFile:
                            TransmitFile(client);
                            break;
                    }
                }
                finally
                {
                    client.Shutdown(SocketShutdown.Both);
                    client.Close();
                }
            }
        }
        // TODO Enable when/if there is a need for the ability to change culture
        private static ServicesGameServer Initialize(CultureInfo activeCulture, uint ip, ushort steamPort, ushort gamePort, ushort queryPort, ServerMode serverMode, string versionString)
        {
            if (activeCulture == null)
            {
                throw new ArgumentNullException("activeCulture", "activeCulture is null.");
            }

            if (Instance != null)
            {
                throw new InvalidOperationException(StringMap.GetString(StringID.OnlyOneInstance, typeof(ServicesGameServer).Name));
            }

            Instance = new ServicesGameServer(activeCulture);
            Instance.Startup(ip, steamPort, gamePort, queryPort, serverMode, versionString);

            return Instance;
        }
Example #36
0
 public HttpServer(string ipAddr, int port, int maxConnectionNumber, ServerMode mode = ServerMode.Standalone)
     : this(IPAddress.Parse(ipAddr), port, maxConnectionNumber, mode)
 {
 }
		public abstract void LaunchLocalServer(Process process, ServerMode mode);
Example #38
0
 private static extern Int32 init(ServerMode serverMode, string IP, int port, NewEvent newEvent, NewIntegerValue newIntegerValue, NewDoubleValue newDoubleValue, NewStringValue newStringValue, IntPtr param);
Example #39
0
 public void ChangeState(ServerModeType state)
 {
     currentState?.OnExitState();
     currentState = states[state];
     currentState.OnEnterState();
 }
 public unsafe ServerStartResult StartPure(uint ip, ushort steamPort, ushort gamePort, ServerMode serverMode, string versionString)
 {
     return ServerStartResult.UnknownError;
 }
		public override void LaunchLocalServer(Process process, ServerMode mode)
		{
		}
Example #42
0
        public MasterServer(ServerConfiguration configuration)
        {
            // TODO:config.
            _caCertificate = new X509Certificate2().LoadFromPemFile("ca.crt");

            _serverMode = configuration.Mode;
            _uri = new UriBuilder("net.tcp", configuration.Address, configuration.Port).Uri;

            if (Path.IsPathRooted(configuration.CertificatePemFile))
                _certificatePemFile = configuration.CertificatePemFile;
            else
            {
                _certificatePemFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                   configuration.CertificatePemFile);
            }
        }
Example #43
0
        private ServiceHost GetServiceHost(ServerMode serverMode)
        {
            ServiceHost serviceHost = new ServiceHost(new JobServiceService(), _uri);

            NetTcpBinding binding;
            if (serverMode == ServerMode.Secure)
            {
                binding = GetSecureBinding();
                SetCertificateOptions(serviceHost);
            }
            else
                binding = GetBinding();

            serviceHost.AddServiceEndpoint(typeof(IJobService), binding, "master");
            serviceHost.AddServiceEndpoint(typeof(IAuthenticationRequest), binding, "authreq");

            return serviceHost;
        }
Example #44
0
 private void StartGame()
 {
     PacketID packetID;
     while (isConnected) {
         packetID = (PacketID)readByte ();
         this.commandCountReceived++;
         packetHistory.Add (packetID);
         double stance;
         int entityID = 0;
         //Console.WriteLine (
         //	"[{0}:{1}:{2}] [{3}]: {4}",this.commandCountReceived,this.packetCountReceived,this.packetSizeReceived,DateTime.Now.ToLongTimeString(),Enum.GetName(typeof(PacketID),packetID));
         switch (packetID) {
         case PacketID.LoginRequest:
             this.player = new Player (this.connectName, this);
             this.player.entityID = readInt ();
             entities [this.player.entityID] = this.player;
             readString ();
             this.levelType = readString ();
             this.serverMode = (ServerMode)readInt ();
             this.dimension = (Dimension)readInt ();
             this.difficulty = (Difficulty)readByte ();
             readByte ();
             this.maxPlayers = readByte ();
             Console.WriteLine ("Entity ID: {0}", this.player.entityID);
             Console.WriteLine ("Level Type: {0}", this.levelType);
             Console.WriteLine ("Server mode: {0}", Enum.GetName (typeof(ServerMode), this.serverMode));
             Console.WriteLine ("Dimension: {0}", Enum.GetName (typeof(Dimension), this.dimension));
             Console.WriteLine ("Difficulty: {0}", Enum.GetName (typeof(Difficulty), this.difficulty));
             Console.WriteLine ("Max players: {0}", this.maxPlayers);
             break;
         case PacketID.DisconnectKick:
             string serverAnswer = readString ();
             Console.WriteLine ("Dissconnected: {0}", serverAnswer);
             isConnected = false;
             isLogged = false;
             break;
         case PacketID.KeepAlive:
             this.SendPacket (new object[]{(byte)PacketID.KeepAlive,readInt ()});
             break;
         case PacketID.PluginMessage:
             string channel = readString ();
             byte[] data = readBytes (readShort ());
             Console.WriteLine ("Plugins data for {0} size: {1}", channel, data.Length);
             break;
         case PacketID.SpawnPosition:
             this.spawnPosition = new XYZ<int> (readInt (), readInt (), readInt ());
             //Console.WriteLine ("Spawn position: X: {0} Y: {1} Z: {2}", X, Y, Z);
             break;
         case PacketID.PlayerAbilities:
             this.player.invulnerability = readBool ();
             this.player.isFlying = readBool ();
             this.player.canFly = readBool ();
             this.player.instantDestroy = readBool ();
             Console.WriteLine (this.player.invulnerability ? "Player cannot take damage" : "Player can take damage");
             Console.WriteLine (this.player.isFlying ? "Player is currently flying" : "Player is't currently flying");
             Console.WriteLine (this.player.canFly ? "Player is able to fly" : "Player is't able to fly");
             Console.WriteLine (this.player.instantDestroy ? "Player can destroy blocks instantly" : "Player can't destroy blocks instantly");
             break;
         case PacketID.TimeUpdate:
             this.time = readLong ();
         //Console.WriteLine ("Time: {0}", time);
             break;
         case PacketID.ChatMessage:
             string msg = readString ();
             if (clearString (msg).Length > 0) {
                 this.chat.Add (clearString (msg));
                 Console.WriteLine ("--|{0}", clearString (msg));
             }
             break;
         case PacketID.PlayerPositionLook:
             lock (this.player) {
                 this.player.position.x = readDouble ();
                 stance = readDouble ();
                 this.player.position.y = readDouble ();
                 this.player.position.z = readDouble ();
                 this.map.updateMap ();
                 this.player.endPosition = this.player.position;
                 this.player.look.yaw = readFloat ();
                 this.player.look.pitch = readFloat ();
                 this.player.onGround = readBool ();
                 this.player.height = stance - this.player.position.y;
             }
             Console.WriteLine (
                 "Absolute position: X:{0:0.####} Y:{1:0.####} Z:{2:0.####} Height:{3:0.###!#}",
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.z, this.player.height);
             Console.WriteLine ("Absolute rotation: X:{0} Y:{1}", this.player.look.yaw, this.player.look.pitch);
             Console.WriteLine ("On ground: {0}", this.player.onGround ? "yes" : "no");
             this.SendPacket (new object[] {
                 (byte)PacketID.PlayerPositionLook,
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.y + this.player.height,
                 this.player.position.z,this.player.look.yaw,this.player.look.pitch,this.player.onGround}
             );
             isLogged = true;
             break;
         case PacketID.Player:
             this.player.onGround = readBool ();
             Console.WriteLine ("On ground: {0}", this.player.onGround ? "yes" : "no");
             break;
         case PacketID.PlayerPosition:
             lock (this.player) {
                 this.player.position.x = readDouble ();
                 this.player.position.y = readDouble ();
                 stance = readDouble ();
                 this.player.position.z = readDouble ();
                 this.map.updateMap ();
                 this.player.height = stance - this.player.position.y;
                 this.player.endPosition = this.player.position;
             }
             Console.WriteLine (
                 "Absolute position: X:{0} Y:{1} Z:{2} Height:{3}",
                 this.player.position.x,
                 this.player.position.y,
                 this.player.position.z,
                 this.player.height
             );
             break;
         case PacketID.SpawnPainting:
             Painting picture = new Painting ();
             picture.entityID = readInt ();
             picture.title = readString ();
             picture.centerPosition.x = readInt ();
             picture.centerPosition.y = readInt ();
             picture.centerPosition.z = readInt ();
             picture.direction = readInt ();
             this.entities [picture.entityID] = picture;
         //Console.WriteLine ("Spawn Painting: {4} X:{0} Y:{1} Z:{2} Direction:{3}", x2, y2, z2, direction, title);
             break;
         case PacketID.EntityHeadLook:
             entityID = readInt ();
             if (entities.ContainsKey (entityID))
                 entities [entityID].headYaw = readByte ();
             else
                 readByte ();
         //Console.WriteLine ("Head yaw: {0} steps", headYew);
             break;
         case PacketID.SpawnMob:
             Mob mob = new Mob ();
             mob.entityID = readInt ();
             mob.type = readByte ();
             mob.position.x = readInt ();
             mob.position.y = readInt ();
             mob.position.z = readInt ();
             mob.look.yaw = readByte ();
             mob.look.pitch = readByte ();
             mob.headYaw = readByte ();
             mob.metadata = readMetadata ();
             entities [mob.entityID] = mob;
         /*Console.WriteLine (
             "Spawn Mob: Type:{0} X:{1} Y:{2} Z:{3} Yaw:{4} Pitch:{5} Head Yaw:{6} Metadate size:{7}",
             type,
             x3,
             y3,
             z3,
             yaw2,
             pitch2,
             headYaw2,
             metadata
         );*/
             break;
         case PacketID.EntityVelocity:
             entityID = readInt ();
             if (entities.ContainsKey (entityID)) {
                 entities [entityID].velocity.x = readShort ();
                 entities [entityID].velocity.y = readShort ();
                 entities [entityID].velocity.z = readShort ();
             } else {
                 readShort ();
                 readShort ();
                 readShort ();
             }
         //Console.WriteLine ("Velocity: X:{0} Y:{1} Z:{1}", vX / 28800.0, vY / 28800.0, vZ / 28800.0);
             break;
         case PacketID.SpawnNamedEntity:
             {
                 OtherPlayer p = new OtherPlayer ();
                 p.entityID = readInt ();
                 p.name = readString ();
                 p.position.x = readInt ();
                 p.position.y = readInt ();
                 p.position.z = readInt ();
                 p.look.yaw = readByte ();
                 p.look.pitch = readByte ();
                 p.currentItem = readShort ();
                 entities [p.entityID] = p;
                 Console.WriteLine (
                 "Player spawned: {3} X:{0} Y:{1} Z:{2} yaw:{4} pitch:{5} withItem:{6}",
                 p.position.x,
                 p.position.y,
                 p.position.z,
                 p.name,
                 p.look.yaw,
                 p.look.pitch,
                 p.currentItem
                 );
             }
             break;
         case PacketID.EntityEquipment:
             entityID = readInt ();
             if (entities.ContainsKey (entityID) && entities [entityID].GetType () == typeof(OtherPlayer)) {
                 OtherPlayer p = (OtherPlayer)entities [entityID];
                 Armor armor = new Armor ();
                 armor.slot = readShort ();
                 armor.itemID = readShort ();
                 armor.damage = readShort ();
                 p.armor [armor.slot] = armor;
                 Console.WriteLine ("Equipment: slot:{0} itemID:{1} damage:{2}", armor.slot, armor.itemID, armor.damage);
             } else {
                 readShort ();
                 readShort ();
                 readShort ();
             }
             break;
         case PacketID.SpawnDroppedItem:
             DroppedItem item = new DroppedItem ();
             item.entityID = readInt ();
             //readInt ();
             item.item = readShort ();
             item.count = readByte ();
             item.data = readShort ();
             item.position.x = readInt ();
             item.position.z = readInt ();
             item.position.y = readInt ();
             item.rotation = readByte ();
             item.pitch = readByte ();
             item.roll = readByte ();
             entities [item.entityID] = item;
             Console.WriteLine (
                 "Dropped item: item:{0}:{2} count:{1} x:{3} y:{4} z:{5} rotation:{6} pitch:{7} roll:{8}",
             item.item,
             item.count,
             item.data,
             item.position.x,
             item.position.y,
             item.position.z,
             item.rotation,
             item.pitch,
             item.roll
             );
             break;
         case PacketID.MapColumnAllocation:
             {
                 int x = readInt ();
                 int z = readInt ();
                 bool mode = readBool ();
                 if (mode) {
                     this.map.initChunk (x, z);
                 } else {
                     this.map.unloadChunk (x, z);
                 }
                 /*Console.WriteLine (
                 "Need to {0} the chunk [{1};{2}]",
                 mode ? "initialize" : "unload",
                 x,
                 z);*/
                 //this.map.WriteMap ();
             }
             break;
         case PacketID.PlayerListItem:
             string name = clearString (readString ());
             bool online = readBool ();
             short ping = readShort ();
             if (online) {
                 playerList [name] = ping;
             } else {
                 playerList.Remove (name);
             }
             Console.WriteLine ("Player:{0} ping:{1} {2} game", name, ping, online ? "enter" : "exit");
             break;
         case PacketID.SetWindowItems:
             byte windowId = readByte ();
             short count2 = readShort ();
         //Console.Write ("Window items: count:{0}", count2);
             for (int i = 0; i<count2; i++) {
                 short id = readShort ();
                 if (id != -1) {
                     byte itemCount = readByte ();
                     short _data = readShort ();
                     if (_data != -1)
                         readBytes (_data);
                     //Console.Write (" [{0}: id: {1} count:{2} dataSize:{3}]", i, id, itemCount, _data);
                 }// else
                 //Console.Write (" [{0};{1}]", i, "Empty");
             }
         //Console.WriteLine ();
             break;
         case PacketID.SetSlot:
             byte winID = readByte ();
             short _slot = readShort ();
             short _id = readShort ();
             if (_id != -1) {
                 byte itemCount = readByte ();
                 short _data = readShort ();
                 if (_data != -1)
                     readBytes (_data);
                 /*Console.WriteLine (
                 "Set slot: [window:{4} {0}: id: {1} count:{2} dataSize:{3}]",
                 _slot,
                 _id,
                 itemCount,
                 _data,
                 winID
             );*/
             } //else
             //Console.WriteLine ("Set slot: [window:{2} {0};{1}]", _slot, "Empty", winID);
             break;
         case PacketID.SpawnExperienceOrb:
             readInt ();
             int x7 = readInt ();
             int y7 = readInt ();
             int z7 = readInt ();
             int count3 = readShort ();
             Console.WriteLine ("Spawn expirience orb: x:{0} y:{1} z:{2} count:{3}", x7, y7, z7, count3);
             break;
         case PacketID.EntityRelativeMove:
             entityID = readInt ();
             sbyte dx = (sbyte)readByte ();
             sbyte dy = (sbyte)readByte ();
             sbyte dz = (sbyte)readByte ();
             if (entities.ContainsKey (entityID) && entities [entityID].GetType () == typeof(OtherPlayer)) {
                 //Console.WriteLine ("Entity move: dx:{0:0.##} dy:{1:0.##} dz:{2:0.##}", dx/32.0, dy/32.0, dz/32.0);
             }
             break;
         case PacketID.EntityLook:
             readInt ();
             byte yaw4 = readByte ();
             byte pitch5 = readByte ();
         //Console.WriteLine ("Entity rotate: yaw:{0} pitch:{1}", yaw4, pitch5);
             break;
         case PacketID.DestroyEntity:
             entities.Remove (readInt ());
         //Console.WriteLine ("Destroy entity");
             break;
         case PacketID.EntityTeleport:
             readInt ();
             int x8 = readInt ();
             int y8 = readInt ();
             int z8 = readInt ();
             byte yaw8 = readByte ();
             byte pitch8 = readByte ();
         //Console.WriteLine ("Entity teleport: X:{0} Y:{1} Z:{2} yaw:{3} pitch:{4}", x8, y8, z8, yaw8, pitch8);
             break;
         case PacketID.BlockAction:
             int x9 = readInt ();
             short y9 = readShort ();
             int z9 = readInt ();
             byte byte1 = readByte ();
             byte byte2 = readByte ();
         //Console.WriteLine ("Block action: X:{0} Y:{1} Z:{2} bytes:[{3},{4}]",x9,y9,z9,byte1,byte2);
             break;
         case PacketID.EntityLookandRelativeMove:
             readInt ();
             int x10 = readByte ();
             int y10 = readByte ();
             int z10 = readByte ();
             byte yaw9 = readByte ();
             byte pitch9 = readByte ();
         //Console.WriteLine ("Entity relative look/move: dX:{0} dY:{1} dZ:{2} Yaw:{3} Pitch:{4}", x10, y10, z10, yaw9, pitch9);
             break;
         case PacketID.EntityMetadata:
             readInt ();
             int msize = readMetadata ();
             break;
         case PacketID.Animation:
             readInt ();
             readByte ();
             break;
         case PacketID.SpawnObjectVehicle:
             /*for (int i =0; i<50 && i<stream.Count; i++) {
                 Console.Write ("{0} ",Convert.ToString (stream[i],16));
             }*/
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             readInt ();
             int fireball = readInt ();
             if (fireball > 0) {
                 readShort ();
                 readShort ();
                 readShort ();
             }
             break;
         case PacketID.EntityStatus:
             readInt ();
             readByte ();
             break;
         case PacketID.IncrementStatistic:
             int statisticID = readInt ();
             byte value = readByte ();
             Console.WriteLine ("Statistic {0} change to {1}", statisticID, value);
             break;
         case PacketID.UpdateHealth:
             this.player.health = readShort ();
             this.player.food = readShort ();
             this.player.saturation = readFloat ();
             Console.WriteLine (
                 "Update health:{0} food:{1} saturation:{2}",
                 this.player.health, this.player.food, this.player.saturation);
             if (this.player.health < 1) {
                 this.SendPacket (new object[] {
                     (byte)PacketID.Respawn,
                     (int)this.dimension,
                     (byte)this.difficulty,
                     (byte)this.serverMode,
                     this.worldHeight,
                     this.levelType
                 }
                 );
             }
             break;
         case PacketID.UseBed:
             readInt ();
             readByte ();
             readInt ();
             readByte ();
             readInt ();
             Console.WriteLine ("use bad");
             break;
         case PacketID.CollectItem:
             readInt ();
             readInt ();
             Console.WriteLine ("Someone pick up items");
             break;
         case PacketID.Entity:
             entities [readInt ()] = new Entity ();
             break;
         case PacketID.AttachEntity:
             readInt ();
             readInt ();
             Console.WriteLine ("Attach player to vehicle");
             break;
         case PacketID.EntityEffect:
             readInt ();
             readByte ();
             readByte ();
             readShort ();
             break;
         case PacketID.RemoveEntityEffect:
             readInt ();
             readByte ();
             break;
         case PacketID.SetExperience:
             readFloat ();
             readShort ();
             readShort ();
             break;
         case PacketID.MapChunks:
             {
                 int x = readInt ();
                 int z = readInt ();
                 bool ground = readBool ();
                 short primarymask = readShort ();
                 short addmask = readShort ();
                 int size = readInt ();
                 readInt ();
                 byte[] chunk = readBytes (size);
                 this.map.loadChunk (x, z, chunk);
                 Console.WriteLine (
                 "Chunk uploaded[{4};{5}] size:{0} ground:{1} mask:{2} mask:{3}", size,ground,Convert.ToString(primarymask,2),Convert.ToString(addmask,2),x,z);
         }
             break;
         case PacketID.MultiBlockChange:
             readInt ();
             readInt ();
             readShort ();
             int _size = readInt ();
             readBytes (_size);
             Console.WriteLine ("Multi block changes size:{0}", _size);
             break;
         case PacketID.BlockChange:
             readInt ();
             readByte ();
             readInt ();
             readByte ();
             readByte ();
             break;
         case PacketID.Explosion:
             readDouble ();
             readDouble ();
             readDouble ();
             readFloat ();
             int size2 = readInt ();
             readBytes (size2 * 3);
             Console.WriteLine ("Explosion records:{0}", size2);
             break;
         case PacketID.SoundParticleEffect:
             readInt ();
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             break;
         case PacketID.ChangeGameState:
             byte byte3 = readByte ();
             byte byte4 = readByte ();
             Console.WriteLine (@"Change game mod: reason: {0} game mod:{1}", byte3, byte4);
             break;
         case PacketID.Thunderbolt:
             readInt ();
             readBool ();
             readInt ();
             readInt ();
             readInt ();
             Console.WriteLine ("Thunderbolt!");
             break;
         case PacketID.OpenWindow:
             readByte ();
             readByte ();
             string winTitle = readString ();
             int slotnum = readByte ();
             Console.WriteLine ("Open window {0} slots:{1}", winTitle, slotnum);
             break;
         case PacketID.CloseWindow:
             readByte ();
             Console.WriteLine ("Close window");
             break;
         case PacketID.UpdateWindowProperty:
             readByte ();
             readShort ();
             readShort ();
             break;
         case PacketID.ItemData:
             readShort ();
             readShort ();
             int textLength = readByte ();
             byte[] text = readBytes (textLength);
             Console.WriteLine ("Item data: {0}", Encoding.ASCII.GetString (text));
             break;
         case PacketID.UpdateTileEntity:
             readInt ();
             readShort ();
             readInt ();
             readByte ();
             readInt ();
             readInt ();
             readInt ();
             break;
         case PacketID.Respawn:
             this.dimension = (Dimension)readInt ();
             this.difficulty = (Difficulty)readByte ();
             this.serverMode = (ServerMode)readByte ();
             this.worldHeight = readShort ();
             this.levelType = readString ();
             Console.WriteLine ("Level Type: {0}", this.levelType);
             Console.WriteLine ("Server mode: {0}", Enum.GetName (typeof(ServerMode), this.serverMode));
             Console.WriteLine ("Dimension: {0}", Enum.GetName (typeof(Dimension), this.dimension));
             Console.WriteLine ("Difficulty: {0}", Enum.GetName (typeof(Difficulty), this.difficulty));
             Console.WriteLine ("World height: {0}", this.worldHeight);
             break;
         case PacketID.ConfirmTransaction:
             readByte ();
             readShort ();
             readBool ();
             Console.WriteLine ("Confirm transaction");
             break;
         case PacketID.CreativeInventoryAction:
             readShort ();
             short _id2 = readShort ();
             if (_id2 != -1) {
                 byte itemCount = readByte ();
                 short _data = readShort ();
                 if (_data != -1)
                     readBytes (_data);
             }
             break;
         case PacketID.UpdateSign:
             readInt ();
             readShort ();
             readInt ();
             string line1 = readString ();
             string line2 = readString ();
             string line3 = readString ();
             string line4 = readString ();
             //Console.WriteLine ("Update sign:{0} {1} {2} {3}", line1, line2, line3, line4);
             break;
         default:
             Console.WriteLine ("Unknown response: {0} ", Convert.ToString ((byte)packetID, 16));
             isConnected = false;
             isLogged = false;
             client.Close ();
             throw new Exception ("Unknown response");
             break;
         }
     }
 }
 /// <summary>
 /// Initializes the native dll and the managed wrapper. Use the returned class to
 /// communicate with the steam API. Can only be used once.
 /// </summary>
 /// <exception cref="ManagedSteam.Exceptions.AlreadyLoadedException"></exception>
 /// <exception cref="ManagedSteam.Exceptions.SteamInitializeFailedException"></exception>
 /// <exception cref="ManagedSteam.Exceptions.SteamInterfaceInitializeFailedException"></exception>
 /// <exception cref="InvalidOperationException">One instance of the Steam class already exists.</exception>
 /// <returns>The instance of the Steam class to be used for all communication with the Steamworks API.</returns>
 public static ServicesGameServer Initialize(uint ip, ushort steamPort, ushort gamePort, ushort queryPort, ServerMode serverMode, string versionString)
 {
     return Initialize(CultureInfo.InvariantCulture, ip, steamPort, gamePort, queryPort, serverMode, versionString);
 }
        public ServerStartResult Start(IPEndPoint serverEndpoint, ushort steamPort, ServerMode serverMode, string versionString, bool gameSocketShare)
        {
            byte[] verPtr_12_cp_0 = Encoding.UTF8.GetBytes(versionString);
            //int verPtr_12_cp_1 = 0;
            if (!gameSocketShare && !this.TestSocket(serverEndpoint))
            {
                return ServerStartResult.PortAlreadyUsed;
            }
            uint arg_4E_0 = serverEndpoint.Address.ToIPv4NetworkOrder();
            int serverEndpoint2;
            if (gameSocketShare)
            {
                serverEndpoint2 = 65535;
            }
            else
            {
                serverEndpoint2 = serverEndpoint.Port + 1;
            }

            //if (<Module>.SteamGameServer_Init(arg_4E_0, steamPort, (ushort)serverEndpoint.Port, (ushort)serverEndpoint2, (EServerMode)serverMode, ref verPtr_12_cp_0[verPtr_12_cp_1]) != null)
            //{
            //    if (gameSocketShare)
            //    {
            //        this.m_masterServerThreadExit = false;
            //        Thread this2 = new Thread(new ParameterizedThreadStart(this.MasterServerUpdaterThread));
            //        this.m_masterServerUpdaterThread = this2;
            //        this2.IsBackground = true;
            //        this.m_masterServerUpdaterThread.Start(serverEndpoint);
            //    }
            //    Peer2Peer.NetworkingEnabled = true;
            //    return ServerStartResult.OK;
            //}
            return ServerStartResult.UnknownError;
        }
 public override void LaunchLocalServer(Process process, ServerMode mode)
 {
 }
 /// <summary>
 /// Разобрать параметры командной строки.
 /// </summary>
 /// <param name="args">Параметры командной строки.</param>
 private void ParseCommandLine(string[] args)
 {
     const string dictionaryFileNameSwitch = "-F=";
     const string PortNumberSwitch = "-P=";
     foreach (string argument in args)
     {
         if (argument.StartsWith(dictionaryFileNameSwitch, StringComparison.CurrentCultureIgnoreCase))
             this.dictionaryFileName = argument.Substring(dictionaryFileNameSwitch.Length);
         if (argument.StartsWith(PortNumberSwitch, StringComparison.CurrentCultureIgnoreCase))
             this.portNumber = int.Parse(argument.Substring(PortNumberSwitch.Length), CultureInfo.CurrentCulture);
     }
     if ((!string.IsNullOrEmpty(dictionaryFileName) && portNumber >= 0))
         this.mode = ServerMode.NormalStart;
 }
Example #49
0
 public HttpServer(IPAddress ipAddr, int port, int maxConnectionNumber, ServerMode mode = ServerMode.Standalone)
     : this(new IPEndPoint(ipAddr, port), maxConnectionNumber, mode)
 {
 }
Example #50
0
 public HttpServer(IPEndPoint ipEndPoint, int maxConnectionNumber, ServerMode mode = ServerMode.Standalone)
     : base(ipEndPoint, maxConnectionNumber)
 {
     Mode = mode;
 }
Example #51
0
 public GprsDtuServer(int port, int keepLiveInterval = 200, ServerMode mode = ServerMode.SMALL)
 {
     _port             = port;
     _mode             = mode;
     _keepLiveInterval = keepLiveInterval;
 }
        private void Startup(uint ip, ushort steamPort, ushort gamePort, ushort queryPort, ServerMode serverMode, string versionString)
        {
            if (NativeHelpers.ServicesGameServer_GetSteamLoadStatus() == LoadStatus.NotLoaded)
            {
                // Only startup the native parts if they are not loaded yet
                if (!NativeMethods.ServicesGameServer_Startup(Constants.VersionInfo.InterfaceID, ip, steamPort, gamePort, queryPort, (int)serverMode, versionString))
                {
                    // Setup failed!
                    Instance = null;
                    ErrorCodes error = NativeHelpers.ServicesGameServer_GetErrorCode();
                    if (error == ErrorCodes.InvalidInterfaceVersion)
                    {
                        Error.ThrowError(ErrorCodes.InvalidInterfaceVersion,
                            NativeMethods.ServicesGameServer_GetInterfaceVersion(), Constants.VersionInfo.InterfaceID);
                    }
                    else
                    {
                        Error.ThrowError(error);
                    }
                }
            }

            serviceJobs = new JobManager();
            serviceJobs.AddJob(new DelegateJob(() => RegisterManagedCallback(), () => RemoveManagedCallback()));
            serviceJobs.AddJob(new DelegateJob(() => gameServer = new GameServer(), () => gameServer.ReleaseManagedResources()));
            serviceJobs.AddJob(new DelegateJob(() => gameServerStats = new GameServerStats(), () => gameServerStats.ReleaseManagedResources()));

            serviceJobs.RunCreateJobs();
        }
Example #53
0
 public abstract void LaunchLocalServer(Process process, ServerMode mode);
Example #54
0
 public void CustomServer()
 {
     server        = new ServerMode(AppConfig.SocketUrl, AppConfig.SocketPort);
     serverBundle  = new WebServerMode(AppConfig.HttpUrl, AppConfig.HttPort);
     serverWebHttp = new WebServerMode(AppConfig.HttpUrl, AppConfig.HttPort);
 }
Example #55
0
        /// <summary>
        /// Create a named pipe instance.
        /// </summary>
        /// <param name="pipeName">Local name (the part after \\.\pipe\)</param>
        public static NamedPipeStream Create(string pipeName, ServerMode mode)
        {
            IntPtr handle = IntPtr.Zero;
            string name = @"\\.\pipe\" + pipeName;

            handle = CreateNamedPipe(
                name,
                (uint)mode,
                PIPE_TYPE_BYTE | PIPE_WAIT,
                PIPE_UNLIMITED_INSTANCES,
                0, // outBuffer,
                1024, // inBuffer,
                NMPWAIT_WAIT_FOREVER,
                IntPtr.Zero);
            if (handle.ToInt32() == INVALID_HANDLE_VALUE)
            {
                throw new Win32Exception("Error creating named pipe " + name + " . Internal error: " + Marshal.GetLastWin32Error().ToString());
            }
            // Set members persistently...
            NamedPipeStream self = new NamedPipeStream();
            self._handle = handle;
            switch (mode)
            {
                case ServerMode.InboundOnly:
                    self._mode = FileAccess.Read;
                    break;
                case ServerMode.OutboundOnly:
                    self._mode = FileAccess.Write;
                    break;
                case ServerMode.Bidirectional:
                    self._mode = FileAccess.ReadWrite;
                    break;
            }
            return self;
        }
 public AuthenticationRequestProxy(ServerConfiguration configuration)
 {
     _serverMode = configuration.Mode;
     _uri = new UriBuilder("net.tcp", configuration.Address, configuration.Port, "authreq").Uri;
 }