/// <summary> /// Server accept socket event, create a new session for the socket. /// </summary> /// <param name="socket"></param> public static void ServerOnAcceptSocketEvent(SilverSocket socket) { try { Client session = new Client(socket); } catch (Exception ex) { error(ex.ToString()); } }
/// <summary> /// Check the socket's ip in the whitelist + add it to the clients list /// </summary> /// <param name="socket"></param> public static void ServerOnAcceptSocketEvent(SilverSocket socket) { try { if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\whitelist.txt")) { File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\whitelist.txt","127.0.0.1"); } StreamReader Reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\whitelist.txt"); lock (Clients) { string[] splitIP = socket.IP.Split(':'); if (Reader.ReadToEnd().Contains(splitIP[0])) { // IP Whitelisted check 1/1 Client _client = new Client(socket); // Add the connected socket to the client list Clients.Add(_client); _client.info.ip = splitIP[0]; // splitIP[0] = players ip, splitIP[1] = players port } else { Error.Invoke("'" + socket.IP + "', is not whitelisted yet."); // Optional } Reader.Dispose(); // Optional } } catch (Exception ex) { Error.Invoke(ex.ToString()); } }