Advertisement
Guest User

Untitled

a guest
May 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using System.Threading;
  7. using System.Net;
  8. using System.IO;
  9.  
  10. namespace Minerva.RCon
  11. {
  12.     class RConServer
  13.     {
  14.         private Thread rconThread;
  15.         private int rconPort;
  16.         private string rconUser, rconPass;
  17.         private TcpListener rconListener;
  18.         private NetworkStream rconStream;
  19.         private IPAddress rconIP;
  20.         private TcpClient rconClient;
  21.         private StreamWriter rconWrite;
  22.         private StreamReader rconRead;
  23.  
  24.         public RConServer()
  25.         {
  26.             LoadConfiguration();
  27.             rconListener = new TcpListener(rconIP, rconPort);
  28.             rconThread = new Thread(new ThreadStart(ListenForRConClients));
  29.             rconThread.Start();
  30.         }
  31.  
  32.         private void ListenForRConClients()
  33.         {
  34.             Console.WriteLine("RConSvr listening for clients on {0}", rconListener.LocalEndpoint);
  35.  
  36.             while (true)
  37.             {
  38.                 // blocks until a client has connected to the server
  39.                 TcpClient client = this.rconListener.AcceptTcpClient();
  40.  
  41.                 Console.WriteLine("Client {0} connected to RConSvr", client.Client.RemoteEndPoint);
  42.  
  43.                 // Create a thread to handle communication with connected client
  44.                 Thread clientThread = new Thread(new ParameterizedThreadStart(HandleRConComm));
  45.                 clientThread.Start(client);
  46.             }
  47.         }
  48.  
  49.         private void HandleRConComm(object client)
  50.         {
  51.             rconClient = (TcpClient)client;
  52.             rconStream = rconClient.GetStream();
  53.  
  54.             int bytesRead;
  55.  
  56.             rconWrite.WriteLine("[Minerva RCon Server]");
  57.             rconWrite.WriteLine("Authentication Required!");
  58.             rconWrite.WriteLine("Please enter your username:");
  59.  
  60.  
  61.         }
  62.  
  63.         void LoadConfiguration()
  64.         {
  65.             IniReader rconConf = new IniReader("conf/RConSvr.ini");
  66.  
  67.             rconIP = IPAddress.Parse(rconConf.ReadString("listen", "ip"));
  68.             rconPort = rconConf.ReadInteger("listen", "port");
  69.             rconUser = rconConf.ReadString("auth", "user");
  70.             rconPass = rconConf.ReadString("auth", "password");
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement