Ejemplo n.º 1
0
 static void OnSessionEstablished(RakNetSession session)
 {
     Console.WriteLine("RakNet session established to Rcon server.");
     session.PacketConstructor   += OnPacketParse;
     session.PacketReceived      += OnPacketReceived;
     session.SessionDisconnected += OnSessionDisconnected;
     Session = session;
 }
Ejemplo n.º 2
0
        static void OnPacketReceived(RakNetSession session, Packet packet)
        {
            if (packet is DosUnknown87)
            {
                // Unknown.
            }
            else if (packet is DosEnumerationList)
            {
                if (!Executed)
                {
                    Console.WriteLine("Sending console command:");
                    Console.WriteLine("> " + Command + " " + String.Join(" ", Arguments));
                    var consoleCmd = new DosSendConsoleCommand
                    {
                        Command   = Command,
                        Arguments = Arguments
                    };
                    session.SendEncapsulated(consoleCmd, EncapsulatedReliability.ReliableOrdered);
                }

                ReceivedEvents = true;
            }
            else if (packet is DosConsoleResponse)
            {
                bool hasResult = false;
                var  lines     = (packet as DosConsoleResponse).Lines;
                foreach (var line in lines)
                {
                    switch (line.Level)
                    {
                    case 4: Console.ForegroundColor = ConsoleColor.Green; hasResult = true; break;

                    case 5: Console.ForegroundColor = ConsoleColor.Red; hasResult = true; break;

                    default: Console.ResetColor(); break;
                    }
                    Console.WriteLine(line.Line);
                }
                Console.ResetColor();
                Executed       = true;
                ReceivedEvents = true;

                if (hasResult)
                {
                    var disconnectCmd = new DosDisconnectConsole();
                    Session.SendEncapsulated(disconnectCmd, EncapsulatedReliability.ReliableOrdered);
                }
            }
            else
            {
                throw new Exception("Unhandled DOS encapsulated packet");
            }
        }
Ejemplo n.º 3
0
        static void OnSessionDisconnected(RakNetSession session)
        {
            if (!Executed)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Received DisconnectionNotification before console command could be sent.");
                Console.ResetColor();
            }
            else
            {
                Console.WriteLine("Closed connection to Rcon server.");
            }

            Environment.Exit(0);
        }
Ejemplo n.º 4
0
 private void HandleConnectionResponse2(IPEndPoint address, OpenConnectionResponse2 response)
 {
     Session = new RakNetSession(this, address, ClientId);
     SessionEstablished(Session);
     Session.OnConnected();
 }