forked from fredriksa/WoWLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerContainer.cs
101 lines (79 loc) · 2.55 KB
/
ServerContainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Launcher
{
public class ServerContainer
{
private List<Server> servers = new List<Server>();
private Form1 form;
public ServerContainer(Form1 form)
{
this.form = form;
}
public void addServer(Server server)
{
servers.Add(server);
form.updateServerList();
}
public void addServer(string file)
{
Server? server = ServerReader.readSingle(file);
if (server == null)
{
Console.WriteLine("COULD NOT LOAD SERVER");
return;
}
servers.Add((Server) server);
form.updateServerList();
}
public void addServer(string file, string directoryPath)
{
ServerReader reader = new ServerReader();
Server? server = ServerReader.readSingle(file);
if (server == null) return;
Server srv = (Server)server;
srv.clientDirectory = directoryPath;
srv.locale = ClientHelper.localeVersion(srv);
servers.Add(srv);
form.updateServerList();
}
public void addServers(List<Server> _servers)
{
servers.AddRange(_servers);
}
public void removeServer(string serverName)
{
Server? removeTarget = null;
foreach (Server server in servers)
if (server.name == serverName)
removeTarget = server;
if (removeTarget != null)
servers.Remove((Server)removeTarget);
}
public Nullable<Server> getServerByName(string name)
{
foreach (Server server in servers)
if (server.name == name)
return server;
return null;
}
public void updateStatus(Server _server, string status)
{
Server? target = null;
foreach (Server server in servers)
if (server.name == _server.name)
target = server;
if (target == null) return;
Server trgt = (Server)target;
servers.Remove(trgt);
trgt.status = status;
servers.Add(trgt);
}
public List<Server> getServers() { return servers; }
public void setServers(List<Server> servers) { this.servers = servers; }
}
}