Code-style fixes
This commit is contained in:
parent
7ccd65dc68
commit
0bc523a2e9
@ -13,14 +13,14 @@ namespace MafiaClient
|
|||||||
{
|
{
|
||||||
public class ServerConnection
|
public class ServerConnection
|
||||||
{
|
{
|
||||||
private readonly String _host = "localhost";
|
private readonly string _host = "localhost";
|
||||||
private readonly int _port = 25743;
|
private readonly int _port = 25743;
|
||||||
private readonly Socket _socket;
|
private readonly Socket _socket;
|
||||||
private readonly Thread _thread;
|
private readonly Thread _thread;
|
||||||
private bool _breakFlag;
|
private bool _breakFlag;
|
||||||
private bool _connected;
|
private bool _connected;
|
||||||
|
|
||||||
public ServerConnection(String ip)
|
public ServerConnection(string ip)
|
||||||
{
|
{
|
||||||
if (ip.Contains(':'))
|
if (ip.Contains(':'))
|
||||||
{
|
{
|
||||||
@ -51,19 +51,19 @@ namespace MafiaClient
|
|||||||
_connected = true;
|
_connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddMessageToChat(String chatName, ListBoxItem message)
|
public void AddMessageToChat(string chatName, ListBoxItem message)
|
||||||
{
|
{
|
||||||
ItemsRepeater listBoxes = MainWindow.Instance.Find<ItemsRepeater>(chatName);
|
ItemsRepeater listBoxes = MainWindow.Instance.Find<ItemsRepeater>(chatName);
|
||||||
if (listBoxes.Items == null || listBoxes.Items.GetType() != typeof(List<ListBoxItem>))
|
if (listBoxes.Items == null || listBoxes.Items.GetType() != typeof(List<ListBoxItem>))
|
||||||
{
|
{
|
||||||
List<ListBoxItem> items = new List<ListBoxItem>();
|
List<ListBoxItem> items = new();
|
||||||
items.Add(message);
|
items.Add(message);
|
||||||
listBoxes.Items = items;
|
listBoxes.Items = items;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<ListBoxItem> items = (List<ListBoxItem>) listBoxes.Items;
|
List<ListBoxItem> items = (List<ListBoxItem>) listBoxes.Items;
|
||||||
List<ListBoxItem> list = new List<ListBoxItem>();
|
List<ListBoxItem> list = new();
|
||||||
list.AddRange(items);
|
list.AddRange(items);
|
||||||
list.Add(message);
|
list.Add(message);
|
||||||
listBoxes.Items = list;
|
listBoxes.Items = list;
|
||||||
@ -100,7 +100,7 @@ namespace MafiaClient
|
|||||||
{
|
{
|
||||||
while (!_breakFlag)
|
while (!_breakFlag)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new();
|
||||||
byte[] data = new byte[256];
|
byte[] data = new byte[256];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -146,13 +146,13 @@ namespace MafiaClient
|
|||||||
"/" +
|
"/" +
|
||||||
((WelcomePacket) packet).MaxPlayers;
|
((WelcomePacket) packet).MaxPlayers;
|
||||||
MainWindow.Instance.ShowGameQueueScreen();
|
MainWindow.Instance.ShowGameQueueScreen();
|
||||||
Party party = new Party
|
Party party = new()
|
||||||
{
|
{
|
||||||
ID = _host + ":" + _port,
|
ID = _host + ":" + _port,
|
||||||
Size = ((WelcomePacket) packet).Players,
|
Size = ((WelcomePacket) packet).Players,
|
||||||
Max = ((WelcomePacket) packet).MaxPlayers
|
Max = ((WelcomePacket) packet).MaxPlayers
|
||||||
};
|
};
|
||||||
Secrets secrets = new Secrets
|
Secrets secrets = new()
|
||||||
{
|
{
|
||||||
JoinSecret = _host + ":" + _port + "/join",
|
JoinSecret = _host + ":" + _port + "/join",
|
||||||
SpectateSecret = _host + ":" + _port + "/spectate"
|
SpectateSecret = _host + ":" + _port + "/spectate"
|
||||||
@ -204,7 +204,7 @@ namespace MafiaClient
|
|||||||
_breakFlag = true;
|
_breakFlag = true;
|
||||||
break;
|
break;
|
||||||
case PacketType.MessageReceivePacket:
|
case PacketType.MessageReceivePacket:
|
||||||
ListBoxItem message = new ListBoxItem();
|
ListBoxItem message = new();
|
||||||
if (((MessageReceivePacket) packet).IsSystem)
|
if (((MessageReceivePacket) packet).IsSystem)
|
||||||
{
|
{
|
||||||
message.Content = ((MessageReceivePacket) packet).Text;
|
message.Content = ((MessageReceivePacket) packet).Text;
|
||||||
@ -240,13 +240,13 @@ namespace MafiaClient
|
|||||||
break;
|
break;
|
||||||
case Role.Don:
|
case Role.Don:
|
||||||
MainWindow.Instance.HideAll();
|
MainWindow.Instance.HideAll();
|
||||||
List<ListBoxItem> items = new List<ListBoxItem>();
|
List<ListBoxItem> items = new();
|
||||||
MainWindow.Instance.ShowVotingActive("Ты Дон, выбери кого убить!");
|
MainWindow.Instance.ShowVotingActive("Ты Дон, выбери кого убить!");
|
||||||
foreach (Player player in players)
|
foreach (Player player in players)
|
||||||
{
|
{
|
||||||
ListBoxItem item = new ListBoxItem
|
ListBoxItem item = new()
|
||||||
{
|
{
|
||||||
Content = player.Id.ToString() + ") " + player.Name
|
Content = player.Id + ") " + player.Name
|
||||||
};
|
};
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
@ -259,9 +259,9 @@ namespace MafiaClient
|
|||||||
MainWindow.Instance.ShowVotingActive("Ты Мафия, выбери кого убить!");
|
MainWindow.Instance.ShowVotingActive("Ты Мафия, выбери кого убить!");
|
||||||
foreach (Player player in players)
|
foreach (Player player in players)
|
||||||
{
|
{
|
||||||
ListBoxItem item = new ListBoxItem
|
ListBoxItem item = new()
|
||||||
{
|
{
|
||||||
Content = player.Id.ToString() + ") " + player.Name
|
Content = player.Id + ") " + player.Name
|
||||||
};
|
};
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
@ -295,7 +295,7 @@ namespace MafiaClient
|
|||||||
{
|
{
|
||||||
case Role.Citizen:
|
case Role.Citizen:
|
||||||
case Role.Died:
|
case Role.Died:
|
||||||
String rol = ((GameStageChangedPacket) packet).Role == Role.Citizen
|
string rol = ((GameStageChangedPacket) packet).Role == Role.Citizen
|
||||||
? "Мирный житель"
|
? "Мирный житель"
|
||||||
: "Мёртв";
|
: "Мёртв";
|
||||||
MainWindow.Instance.ShowVotingPassive("Ты " + rol + "!");
|
MainWindow.Instance.ShowVotingPassive("Ты " + rol + "!");
|
||||||
@ -305,14 +305,14 @@ namespace MafiaClient
|
|||||||
rol = ((GameStageChangedPacket) packet).Role == Role.Mafia
|
rol = ((GameStageChangedPacket) packet).Role == Role.Mafia
|
||||||
? "Мафия"
|
? "Мафия"
|
||||||
: "Дон";
|
: "Дон";
|
||||||
List<ListBoxItem> items = new List<ListBoxItem>();
|
List<ListBoxItem> items = new();
|
||||||
MainWindow.Instance.ShowVotingActive("Ты " + rol + ", выбери кого убить!");
|
MainWindow.Instance.ShowVotingActive("Ты " + rol + ", выбери кого убить!");
|
||||||
MainWindow.Instance.FindControl<ListBox>("GameVotingActiveSelect").Items = null;
|
MainWindow.Instance.FindControl<ListBox>("GameVotingActiveSelect").Items = null;
|
||||||
foreach (Player player in players)
|
foreach (Player player in players)
|
||||||
{
|
{
|
||||||
ListBoxItem item = new ListBoxItem
|
ListBoxItem item = new()
|
||||||
{
|
{
|
||||||
Content = player.Id.ToString() + ") " + player.Name
|
Content = player.Id + ") " + player.Name
|
||||||
};
|
};
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ namespace MafiaServer
|
|||||||
{
|
{
|
||||||
public class Game
|
public class Game
|
||||||
{
|
{
|
||||||
private readonly List<PlayerSocketWorker> _players = new List<PlayerSocketWorker>();
|
private readonly List<PlayerSocketWorker> _players = new();
|
||||||
private readonly List<PlayerRole> _playerRolesAtStart = new List<PlayerRole>();
|
private readonly List<PlayerRole> _playerRolesAtStart = new();
|
||||||
private bool _isStarted;
|
private bool _isStarted;
|
||||||
private GameState _gameState = GameState.NotStarted;
|
private GameState _gameState = GameState.NotStarted;
|
||||||
private readonly List<PlayerSocketWorker> _votesRemain = new List<PlayerSocketWorker>();
|
private readonly List<PlayerSocketWorker> _votesRemain = new();
|
||||||
private readonly List<PlayerSocketWorker> _mafia = new List<PlayerSocketWorker>();
|
private readonly List<PlayerSocketWorker> _mafia = new();
|
||||||
private readonly Dictionary<int, int> _mafiaVotes = new Dictionary<int, int>();
|
private readonly Dictionary<int, int> _mafiaVotes = new();
|
||||||
private readonly Dictionary<int, int> _dayVote = new Dictionary<int, int>();
|
private readonly Dictionary<int, int> _dayVote = new();
|
||||||
private Timer _voteStartTimer;
|
private Timer _voteStartTimer;
|
||||||
|
|
||||||
public void ConnectPlayer(PlayerSocketWorker player)
|
public void ConnectPlayer(PlayerSocketWorker player)
|
||||||
@ -223,7 +223,7 @@ namespace MafiaServer
|
|||||||
_votesRemain.Add(player);
|
_votesRemain.Add(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Player> players = GetPlayersRoles();
|
var players = GetPlayersRoles();
|
||||||
|
|
||||||
foreach (var player in _players)
|
foreach (var player in _players)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ namespace MafiaServer
|
|||||||
public class MainConfig
|
public class MainConfig
|
||||||
{
|
{
|
||||||
public int Port = 25743;
|
public int Port = 25743;
|
||||||
public String ServerName = "Test server";
|
public string ServerName = "Test server";
|
||||||
public int MaxPlayers = 20;
|
public int MaxPlayers = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,8 +22,8 @@ namespace MafiaServer
|
|||||||
public PlayerSocketWorker(Socket socket)
|
public PlayerSocketWorker(Socket socket)
|
||||||
{
|
{
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
StringBuilder builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
byte[] data = new byte[256];
|
var data = new byte[256];
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var bytes = _socket.Receive(data);
|
var bytes = _socket.Receive(data);
|
||||||
@ -65,9 +65,9 @@ namespace MafiaServer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
int bytes = 0;
|
var bytes = 0;
|
||||||
byte[] data = new byte[256];
|
var data = new byte[256];
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
bytes = _socket.Receive(data);
|
bytes = _socket.Receive(data);
|
||||||
@ -76,8 +76,8 @@ namespace MafiaServer
|
|||||||
|
|
||||||
Console.WriteLine(builder.ToString());
|
Console.WriteLine(builder.ToString());
|
||||||
|
|
||||||
List<Packet> packets = PacketConverter.ToPacket(builder.ToString());
|
var packets = PacketConverter.ToPacket(builder.ToString());
|
||||||
foreach (Packet packet in packets)
|
foreach (var packet in packets)
|
||||||
{
|
{
|
||||||
WorkPacket(packet);
|
WorkPacket(packet);
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ namespace MafiaServer
|
|||||||
public static class PlayerSocketWorkerUtils {
|
public static class PlayerSocketWorkerUtils {
|
||||||
public static PlayerSocketWorker FindPlayerById(this List<PlayerSocketWorker> original, int id)
|
public static PlayerSocketWorker FindPlayerById(this List<PlayerSocketWorker> original, int id)
|
||||||
{
|
{
|
||||||
foreach (PlayerSocketWorker player in original)
|
foreach (var player in original)
|
||||||
{
|
{
|
||||||
if (player.Id == id) return player;
|
if (player.Id == id) return player;
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace MafiaServer
|
namespace MafiaServer
|
||||||
{
|
{
|
||||||
static class MafiaServer
|
internal static class MafiaServer
|
||||||
{
|
{
|
||||||
private static Server _server;
|
private static Server _server;
|
||||||
private static Boolean _breakFlag;
|
private static bool _breakFlag;
|
||||||
public static Game Game;
|
public static Game Game;
|
||||||
|
|
||||||
static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Settings.Initialize();
|
Settings.Initialize();
|
||||||
Settings.Save();
|
Settings.Save();
|
||||||
@ -16,7 +16,7 @@ namespace MafiaServer
|
|||||||
_server = new Server();
|
_server = new Server();
|
||||||
while (!_breakFlag)
|
while (!_breakFlag)
|
||||||
{
|
{
|
||||||
String input = Console.ReadLine();
|
var input = Console.ReadLine();
|
||||||
if(input == null) continue;
|
if(input == null) continue;
|
||||||
switch (input.Split(" ")[0].ToLower())
|
switch (input.Split(" ")[0].ToLower())
|
||||||
{
|
{
|
||||||
|
@ -11,8 +11,8 @@ namespace MafiaServer
|
|||||||
{
|
{
|
||||||
private readonly Socket _socket;
|
private readonly Socket _socket;
|
||||||
private readonly Thread _acceptor;
|
private readonly Thread _acceptor;
|
||||||
private readonly List<Socket> _clientSockets = new List<Socket>();
|
private readonly List<Socket> _clientSockets = new();
|
||||||
private readonly List<Thread> _clientThreads = new List<Thread>();
|
private readonly List<Thread> _clientThreads = new();
|
||||||
|
|
||||||
public Server()
|
public Server()
|
||||||
{
|
{
|
||||||
@ -26,14 +26,14 @@ namespace MafiaServer
|
|||||||
Console.WriteLine("Server started!");
|
Console.WriteLine("Server started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop(String reason)
|
public void Stop(string reason)
|
||||||
{
|
{
|
||||||
_acceptor.Interrupt();
|
_acceptor.Interrupt();
|
||||||
foreach (Thread thread in _clientThreads)
|
foreach (var thread in _clientThreads)
|
||||||
{
|
{
|
||||||
thread.Interrupt();
|
thread.Interrupt();
|
||||||
}
|
}
|
||||||
foreach (Socket socket in _clientSockets)
|
foreach (var socket in _clientSockets)
|
||||||
{
|
{
|
||||||
if (socket.Connected)
|
if (socket.Connected)
|
||||||
{
|
{
|
||||||
@ -46,9 +46,9 @@ namespace MafiaServer
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Socket playerSocket = _socket.Accept();
|
var playerSocket = _socket.Accept();
|
||||||
PlayerSocketWorker playerSocketWorker = new PlayerSocketWorker(playerSocket);
|
var playerSocketWorker = new PlayerSocketWorker(playerSocket);
|
||||||
Thread thread = new Thread(playerSocketWorker.Run);
|
var thread = new Thread(playerSocketWorker.Run);
|
||||||
_clientSockets.Add(playerSocket);
|
_clientSockets.Add(playerSocket);
|
||||||
_clientThreads.Add(thread);
|
_clientThreads.Add(thread);
|
||||||
thread.Start();
|
thread.Start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user