79 lines
2.1 KiB
Plaintext
79 lines
2.1 KiB
Plaintext
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.IO;
|
|
|
|
namespace SN_Server
|
|
{
|
|
public class ServerIdentlist
|
|
{
|
|
private const string fileName = "iplist.txt";
|
|
|
|
private List<ServerIdent> ip_list;
|
|
public List<ServerIdent> IP_list
|
|
{
|
|
get { return ip_list; }
|
|
//set { ip_list = value; }
|
|
}
|
|
|
|
public ServerIdentlist()
|
|
{
|
|
ip_list = new List<ServerIdent>();
|
|
|
|
if (File.Exists(fileName))
|
|
{
|
|
// Open the stream and read it back.
|
|
using (StreamReader file = new System.IO.StreamReader(fileName))
|
|
{
|
|
string line;
|
|
while ((line = file.ReadLine()) != null)
|
|
{
|
|
ServerIdent si = new ServerIdent();
|
|
Console.WriteLine(line);
|
|
|
|
//parse line
|
|
parse(line,ref si);
|
|
|
|
//add to list
|
|
ip_list.Add(si);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void parse(string line, ref ServerIdent si)
|
|
{
|
|
if (line != null)
|
|
{
|
|
string[] temp = line.Split(':');
|
|
si.IP = temp[0];
|
|
si.Port = Int32.Parse(temp[1]);
|
|
}
|
|
}
|
|
|
|
public void UpdateFile()
|
|
{
|
|
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName))
|
|
{
|
|
foreach (ServerIdent si in ip_list)
|
|
{
|
|
file.WriteLine(si.IP + ":" + si.Port);
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("CS ip list updated to file:" + fileName);
|
|
}
|
|
|
|
public void Print()
|
|
{
|
|
Console.WriteLine("Control server IP list:");
|
|
foreach (ServerIdent si in ip_list)
|
|
{
|
|
Console.WriteLine("IP:" + si.IP + " port:" + si.Port);
|
|
}
|
|
}
|
|
}
|
|
}
|