Flush() public method

public Flush ( ) : void
return void
Example #1
0
 /// <summary>
 /// Sends a NetStruct over some (network backed) stream
 /// </summary>
 /// <param name="s">Stream to write to</param>
 public void Send(plBufferedStream s)
 {
     if (MsgID is UInt32)
         s.WriteUInt((uint)MsgID);
     else if (MsgID is UInt16)
         s.WriteUShort((ushort)MsgID);
     else
         throw new NotSupportedException();
     Write(s);
     s.Flush();
 }
Example #2
0
        protected override void IOnConnect()
        {
            fStream = new plBufferedStream(new NetworkStream(fSocket, false));
            fConnHdr.Write(fStream);
            fStream.WriteUInt(12); // Complete BS below, but who cares?
            fStream.WriteUInt(0);
            fStream.WriteUInt(0);
            fStream.Flush();

            // File connections send an Int32 length, then the Int32 msgID
            fStream.PrependLength = true;
            base.IOnConnect();
        }
Example #3
0
        protected override void IOnConnect()
        {
            plBufferedStream bs = new plBufferedStream(new NetworkStream(fSocket, false));
            fConnHdr.Write(bs);
            bs.WriteInt(20);
            pnHelpers.WriteUuid(bs, Guid.Empty);
            bs.Flush();

            // Encryption
            if (!base.INetCliConnect(bs, 4))
                Close();
            bs.Close();

            // Listen
            base.IOnConnect();
        }
Example #4
0
 private void IWriteNetClientConnect(plBufferedStream s, byte[] seed)
 {
     s.WriteByte(plNetCore.kNetCliConnect);
     s.WriteByte(66);
     s.WriteBytes(seed);
     s.Flush();
 }
Example #5
0
        protected override void IOnConnect()
        {
            // Write out the lobby header & the server header
            plBufferedStream bs = new plBufferedStream(new NetworkStream(fSocket, false));
            fConnHdr.Write(bs);
            bs.Flush();

            // Encryption
            if (!base.INetCliConnect(bs, 2011))
                Close();
            bs.Close();

            // Listen
            base.IOnConnect();
        }
Example #6
-1
        protected bool SetupEncryption(byte[] pubKey, byte[] privKey)
        {
            NetworkStream ns = new NetworkStream(fSocket, false);
            plBufferedStream temp = new plBufferedStream(ns);
            byte[] yData = IReadNetCliConnect(temp);

            if (yData != null) {
                BigNum Y = new BigNum(yData);
                BigNum N = new BigNum(pubKey);
                BigNum K = new BigNum(privKey);

                // Generate some randomness and do Y**K%N to get the key components
                byte[] server_seed = RNG.Random(7);
                BigNum client_seed = Y.PowMod(K, N);
                byte[] seed_data = client_seed.ToLittleArray();

                // Grab the first 7 bytes and xor it with some randomness to make our key
                byte[] key = new byte[7];
                for (int i = 0; i < key.Length; i++)
                    if (i >= seed_data.Length) key[i] = server_seed[i];
                    else key[i] = (byte)(seed_data[i] ^ server_seed[i]);

                // Final setup
                fStream = new plBufferedStream(new pnSocketStream(fSocket, key));
                IWriteNetCliEncrypt(temp, server_seed);

                // Explicitly clean up some resources so that we don't pressure the GC too much.
                // Those explicit finalizers really suck.
                Y.Dispose();
                N.Dispose();
                K.Dispose();
                client_seed.Dispose();
            } else
                // Write the error code to the unencrypted buffer
                temp.WriteByte(plNetCore.kNetCliError);

            temp.Flush();
            temp.Close();
            ns.Close();

            return (yData != null);
        }