/// <summary> /// Initialises a new <see cref="ServerChat"/> instance. /// </summary> /// <param name="netServer"></param> /// <param name="authenticator"></param> /// <param name="userManager"></param> /// <param name="messageHistoryCapacity"></param> public ServerChat(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, int messageHistoryCapacity) { this.netServer = netServer; this.authenticator = authenticator; this.userManager = userManager; this.messageHistoryCapacity = messageHistoryCapacity; this.messageHistory = new List <ChatMessage>(); netServer.RegisterPacketHandler(MODULE_NAME, packetHandler); userManager.OnLogin += loginHandler; }
/// <summary> /// Creates a new <see cref="ServerUserManager"/> instance and loads in the user store from the given path. /// </summary> /// <param name="netServer"><see cref="NetServer"/> instance to bind packet handlers to</param> /// <param name="authenticator"><see cref="ServerAuthenticator"/> to check session validity with</param> /// <param name="userStorePath">Path to user store</param> /// <param name="maxDisplayNameLength">Maximum number of non-format characters users may have in their display name</param> public ServerUserManager(NetServer netServer, ServerAuthenticator authenticator, string userStorePath, int maxDisplayNameLength = 100) { this.netServer = netServer; this.authenticator = authenticator; this.maxDisplayNameLength = maxDisplayNameLength; this.connectedUsers = new Dictionary <string, string>(); Load(userStorePath); netServer.RegisterPacketHandler(MODULE_NAME, packetHandler); netServer.OnConnectionClosed += connectionClosedHandler; }
public ServerTrading(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager) { this.netServer = netServer; this.authenticator = authenticator; this.userManager = userManager; this.activeTrades = new Dictionary <string, Trade>(); this.completedTrades = new Dictionary <string, CompletedTrade>(); netServer.RegisterPacketHandler(MODULE_NAME, packetHandler); userManager.OnLogin += loginEventHandler; }
/// <summary> /// Initialises a new <see cref="ServerChat"/> instance and loads the chat history from the given file. /// </summary> /// <param name="netServer"></param> /// <param name="authenticator"></param> /// <param name="userManager"></param> /// <param name="messageHistoryCapacity"></param> /// <param name="messageHistoryStorePath"></param> public ServerChat(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, int messageHistoryCapacity, string messageHistoryStorePath) : this(netServer, authenticator, userManager, messageHistoryCapacity) { Load(messageHistoryStorePath); }
static void Main(string[] args) { //if (!ConfigurationHelper.Import("NordicConf.json")) { // Console.WriteLine("Configuration import failed, using default values and writing configuration file \"NordicConf.json\"."); // ConfigurationHelper.Export("NordicConf.json"); //} var _hardcodedChallenge = "miner_test"; ServerAuthenticator.Initialize("pubKey.pem", "privKey.pem", ""); ClientAuthenticator.Initialize("pubKey.pem", "privKey.pem", ""); ClientAuthenticator.Add(_hardcodedChallenge, File.ReadAllText("miner_pubKey.pem")); Console.WriteLine("---------- BLOCKCHAIN ----------\n"); Blockchain _nbStructure = new Blockchain(); var gBlock = _nbStructure.GetBlock(0); Console.WriteLine(gBlock.ToString()); //_nbStructure.Add(new BlockData("", IOperation.OPERATION_TYPE.SECURITY_BC_COMPROMISE_NOTICE, "Lol")); Console.WriteLine(_nbStructure.LastBlock().ToString()); Console.WriteLine("Fork Validity: " + _nbStructure.Validity()); Console.WriteLine("\n---------- NODE VAULT ----------\n"); Console.WriteLine("Importing current node credentials..."); TrustVault _vault = new TrustVault(File.ReadAllText("privKey.pem"), File.ReadAllText("pubKey.pem")); Console.WriteLine(_vault.ToJson()); Console.WriteLine("\n----------- NETWORK ------------\n"); Console.WriteLine("Setting up network for 127.0.0.1:1337 (LOCAL ONLY BINDING!)."); Network _net = new Network("127.0.0.1", 1337); if (_net.Setup()) { _net.Start(); Console.WriteLine("Network started on 127.0.0.1:1337."); } else Console.WriteLine("Network setup failed."); Console.WriteLine("\n---------- SHAREDCACHE ---------\n"); Console.WriteLine("Building Shared Node Cache for online nodes..."); Console.WriteLine("\tOnly 1 node online."); SharedCache _cache = new SharedCache(); _cache.AddAddress("127.0.0.1"); Console.WriteLine(_cache.ToJson()); Console.WriteLine("\n-------------- RSA -------------\n"); RSA _rsa = new RSA(File.ReadAllText("privKey.pem"), File.ReadAllText("pubKey.pem")); var _signature = _rsa.Sign("makeAwish"); var _verify = _rsa.VerifySignature("makeAwish", _signature, null); var _verify2 = _rsa.VerifySignature("makeAwisha", _signature, null); Console.WriteLine("Signed: " + _signature + "\n\n"); Console.WriteLine("Verify: " + _verify); Console.WriteLine("Verify fake one: " + _verify2); Client cl = new Client(); cl.Connect("ws://127.0.0.1:1337/blt"); bool _sent = false; while (true) { if (WaitOrBreak(_nbStructure.LastBlock())) break; if (!_nbStructure.Validity()) { Console.WriteLine("Blockchain violation detected!"); break; } //try { // if (!_sent) { // IOperation _op = new OperationTransaction("d3vil401", "13.2", "none"); // ClmManager _clm = new ClmManager(_op); // var _buffer = _clm.GetBuffer().Result.ToBase64(); // // cl.Send("ws://127.0.0.1:1337/blt", _buffer); // _sent = true; // } // //} catch (Exception ex) { // Console.WriteLine(ex.Message); //} } }
public static Ice.DispatchStatus nameToId___(ServerAuthenticator obj__, IceInternal.Incoming inS__, Ice.Current current__) { checkMode__(Ice.OperationMode.Idempotent, current__.mode); IceInternal.BasicStream is__ = inS__.istr(); is__.startReadEncaps(); string name; name = is__.readString(); is__.endReadEncaps(); IceInternal.BasicStream os__ = inS__.ostr(); int ret__ = obj__.nameToId(name, current__); os__.writeInt(ret__); return Ice.DispatchStatus.DispatchOK; }
public static Ice.DispatchStatus idToTexture___(ServerAuthenticator obj__, IceInternal.Incoming inS__, Ice.Current current__) { checkMode__(Ice.OperationMode.Idempotent, current__.mode); IceInternal.BasicStream is__ = inS__.istr(); is__.startReadEncaps(); int id; id = is__.readInt(); is__.endReadEncaps(); IceInternal.BasicStream os__ = inS__.ostr(); byte[] ret__ = obj__.idToTexture(id, current__); os__.writeByteSeq(ret__); return Ice.DispatchStatus.DispatchOK; }
public static Ice.DispatchStatus getInfo___(ServerAuthenticator obj__, IceInternal.Incoming inS__, Ice.Current current__) { checkMode__(Ice.OperationMode.Idempotent, current__.mode); IceInternal.BasicStream is__ = inS__.istr(); is__.startReadEncaps(); int id; id = is__.readInt(); is__.endReadEncaps(); _System.Collections.Generic.Dictionary<Murmur.UserInfo, string> info; IceInternal.BasicStream os__ = inS__.ostr(); bool ret__ = obj__.getInfo(id, out info, current__); Murmur.UserInfoMapHelper.write(os__, info); os__.writeBool(ret__); return Ice.DispatchStatus.DispatchOK; }
public static Ice.DispatchStatus authenticate___(ServerAuthenticator obj__, IceInternal.Incoming inS__, Ice.Current current__) { checkMode__(Ice.OperationMode.Idempotent, current__.mode); IceInternal.BasicStream is__ = inS__.istr(); is__.startReadEncaps(); string name; name = is__.readString(); string pw; pw = is__.readString(); byte[][] certificates; { int szx__ = is__.readSize(); is__.startSeq(szx__, 1); certificates = new byte[szx__][]; for(int ix__ = 0; ix__ < szx__; ++ix__) { certificates[ix__] = Murmur.CertificateDerHelper.read(is__); is__.endElement(); } is__.endSeq(szx__); } string certhash; certhash = is__.readString(); bool certstrong; certstrong = is__.readBool(); is__.endReadEncaps(); string newname; string[] groups; IceInternal.BasicStream os__ = inS__.ostr(); int ret__ = obj__.authenticate(name, pw, certificates, certhash, certstrong, out newname, out groups, current__); os__.writeString(newname); os__.writeStringSeq(groups); os__.writeInt(ret__); return Ice.DispatchStatus.DispatchOK; }
static void Main() { // Read in the config and initialise the logging module Config = Config.Load(CONFIG_FILE); Logger = new Logger(Config.LogPath, Config.DisplayVerbosity, Config.LogVerbosity); // Set up module instances Connections = new NetServer(new IPEndPoint(Config.Address, Config.Port), Config.MaxConnections); Authenticator = new ServerAuthenticator( netServer: Connections, serverName: Config.ServerName, serverDescription: Config.ServerDescription, authType: Config.AuthType ); UserManager = new ServerUserManager(Connections, Authenticator, Config.MaxDisplayNameLength); Chat = new ServerChat(Connections, Authenticator, UserManager, Config.ChatHistoryLength); Trading = new ServerTrading(Connections, Authenticator, UserManager); // Add handler for ILoggable modules Authenticator.OnLogEntry += ILoggableHandler; UserManager.OnLogEntry += ILoggableHandler; Chat.OnLogEntry += ILoggableHandler; Trading.OnLogEntry += ILoggableHandler; // Load saved data Authenticator.Load(Config.CredentialDatabasePath); UserManager.Load(Config.UserDatabasePath); Chat.Load(Config.ChatHistoryPath); Trading.Load(Config.TradeDatabasePath); // Start listening for connections Connections.Start(); // State our auth type and where we're listening from Logger.Log(Verbosity.INFO, string.Format("Accepting auth type \"{0}\"", Config.AuthType.ToString())); Logger.Log(Verbosity.INFO, string.Format("Phinix server version {0} listening on {1}:{2}", Version, Connections.Endpoint.Address, Connections.Endpoint.Port)); // Set up an exit condition on SIGINT/Ctrl+C Console.CancelKeyPress += shutdownHandler; // Start interpreting commands CommandInterpreter interpreter = new CommandInterpreter(); while (!exiting) { // Wait until we've got a command to interpret string line = Console.ReadLine(); // Don't do anything if the command is empty if (string.IsNullOrEmpty(line)) { continue; } // Break the line down into the command and its arguments List <string> arguments = new List <string>(line.Split(' ')); string command = arguments.First(); arguments.RemoveAt(0); // Remove the command from the argument list // Check if we've been given the exit command // This is checked here to avoid weird workarounds from the interpreter if (command == "exit" || command == "quit" || command == "stop") { shutdownHandler(); break; } // Interpret the command and its arguments interpreter.Run(command, arguments); } }
public ServerTrading(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, string tradeDatabasePath) : this(netServer, authenticator, userManager) { Load(tradeDatabasePath); }