コード例 #1
0
        private void ClientTick(ref Client client)
        {
            statusLabel.Text =
                $"Server {SyncIp}:{SyncPort} ({client.CurrentConnectionStatus})";

            if (client.CurrentConnectionStatus != "Connected")
            {
                if (client.CurrentConnectionStatus == "Disconnected")
                {
                    ResetNetworking();
                }

                return;
            }

            if (MatchValueChanged)
            {
                try
                {
                    client.Send("UpdateMatch", Match.ToJsonString());
                    MatchValueChanged = false;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Can't sent updated match", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    client.Disconnect();
                }
            }

            if (client.PendingUpdate)
            {
                Match = MatchModel.ParseJsonString(client.MatchJson);
            }
        }
コード例 #2
0
        private void ServerTick(ref Server server)
        {
            statusLabel.Text = $"Server started at port {SyncPort} - {server.NumberOfClients} client/s";

            if (MatchValueChanged)
            {
                server.MatchJson = Match.ToJsonString();
                server.SendUpdatedMatchToClients();
            }

            if (server.PendingUpdate)
            {
                Match = MatchModel.ParseJsonString(server.MatchJson);
            }
        }