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