Flush() public method

public Flush ( ) : void
return void
Example #1
0
        void ReconnectionListener()
        {
            Trace.TraceInformation("Reconnection listener Started on {0} : {1}", ipAddress.ToString(), IpPort);
            while (true)
            {
                try
                {
                    var client = listener.AcceptTcpClient();
                    Trace.TraceInformation("Client connected");
                    var stream = client.GetStream();
                    stream.ReadTimeout = 2000;
                    Account theAccount = null;
                    if (game.Configuration != null)
                    {
                        object item;
                        try
                        {
                            item = (new ItemReceiver(stream)).Receive();
                        }
                        catch (Exception)
                        {
                            item = null;
                        }
                        if (!(item is LoginToken) ||
                         !game.Configuration.AccountIds.Any(id => id.token == ((LoginToken)item).token))
                        {
                            client.Close();
                            continue;
                        }
                        int index;
                        for (index = 0; index < game.Configuration.AccountIds.Count; index++)
                        {
                            if (game.Configuration.AccountIds[index].token == ((LoginToken)item).token)
                            {
                                theAccount = game.Configuration.Accounts[index];
                            }
                        }
                    }
                    stream.ReadTimeout = Timeout.Infinite;
                    int indexC = game.Settings.Accounts.IndexOf(theAccount);
                    Trace.Assert(indexC >= 0);
                    lock (handlers[indexC].queueIn) lock (handlers[indexC].queueOut) lock (handlers[indexC].sender) lock (handlers[indexC].receiver)
                                {
                                    handlers[indexC].sender.Flush();
                                    var newRCStream = new RecordTakingOutputStream(stream);
                                    (handlers[indexC].stream as RecordTakingOutputStream).DumpTo(newRCStream);
                                    handlers[indexC].disconnected = false;
                                    newRCStream.Flush();
                                    handlers[indexC].stream = newRCStream;
                                    handlers[indexC].sender = new ItemSender(handlers[indexC].stream);
                                    handlers[indexC].receiver = new ItemReceiver(handlers[indexC].stream);
                                }

                }
                catch (Exception)
                {
                    return;
                }
            }
        }
Example #2
0
        void ReconnectionListener()
        {
            Trace.TraceInformation("Reconnection listener Started on {0} : {1}", ipAddress.ToString(), IpPort);
            while (true)
            {
                try
                {
                    var client = listener.AcceptTcpClient();
                    Trace.TraceInformation("Client connected");
                    var stream = client.GetStream();
                    bool spectatorJoining = false;
                    stream.ReadTimeout = 2000;
                    Account theAccount = null;
                    if (game.Configuration != null)
                    {
                        object item;
                        try
                        {
                            item = (new ItemReceiver(stream)).Receive();
                        }
                        catch (Exception)
                        {
                            item = null;
                        }
                        if (!(item is LoginToken))
                        {
                            client.Close();
                            continue;
                        }
                        if (!game.Configuration.AccountIds.Any(id => id.TokenString == ((LoginToken)item).TokenString))
                        {
                            spectatorJoining = true;
                        }
                        else
                        {
                            int index;
                            for (index = 0; index < game.Configuration.AccountIds.Count; index++)
                            {
                                if (game.Configuration.AccountIds[index].TokenString == ((LoginToken)item).TokenString)
                                {
                                    theAccount = game.Configuration.Accounts[index];
                                }
                            }
                        }
                    }
                    stream.ReadTimeout = Timeout.Infinite;
                    int indexC = game.Settings.Accounts.IndexOf(theAccount);
                    if (spectatorJoining) indexC = numberOfGamers;
                    if (indexC < 0)
                    {
                        client.Close();
                        continue;
                    }
                    lock (handlers[indexC].queueIn) lock (handlers[indexC].queueOut) lock (handlers[indexC].sender) lock (handlers[indexC].receiver)
                    {
                        handlers[indexC].sender.Flush();
                        if (spectatorJoining)
                        {
                            ReplaySplitterStream rpstream = handlers[indexC].stream as ReplaySplitterStream;
                            var tempSender = new ItemSender(stream);
                            tempSender.Send(new CommandItem() { command = Command.Detach, type = ItemType.Int, data = 0 });
                            tempSender.Flush();
                            rpstream.DumpTo(stream);
                            stream.Flush();
                            tempSender.Send(new CommandItem() { command = Command.Attach, type = ItemType.Int, data = 0 });
                            tempSender.Flush();
                            rpstream.AddStream(stream);
                        }
                        else
                        {
                            var newRCStream = new RecordTakingOutputStream(stream);
                            var tempSender = new ItemSender(newRCStream);
                            tempSender.Send(new CommandItem() { command = Command.Detach, type = ItemType.Int, data = 0 });
                            tempSender.Flush();
                            (handlers[indexC].stream as RecordTakingOutputStream).DumpTo(newRCStream);
                            handlers[indexC].disconnected = false;
                            newRCStream.Flush();
                            tempSender.Send(new CommandItem() { command = Command.Attach, type = ItemType.Int, data = 0 });
                            tempSender.Flush();
                            handlers[indexC].stream = newRCStream;
                            handlers[indexC].sender = new ItemSender(handlers[indexC].stream);
                            handlers[indexC].receiver = new ItemReceiver(handlers[indexC].stream);
                        }
                    }

                }
                catch (Exception)
                {
                    return;
                }
            }
        }