コード例 #1
0
        Hashtable unsafepackethandlers = new Hashtable(); // packets which dont have correct sharedsecret, or sharedsecret not yet validated

        #endregion Fields

        #region Constructors

        public NetworkLevel2Connection( NetworkLevel2Controller parent, ConnectionInfo connectioninfo, bool isserver )
        {
            LogFile.WriteLine("NetworkLevel2Connection()");

            networkimplementation = parent.networkimplementation;
            this.connectioninfo = connectioninfo;

            this.parent = parent;
            //this.connection = connectioninfo.Connection;
            this.isserver = isserver;

            lasttimestamp = DateTime.Now;

            packetreferencecontroller = new NetPacketReferenceController( this, isserver );
            sharedsecretexchange = new NetSharedSecretExchange( this, isserver );
            //sharedsecretexchange.Tick();
        }
コード例 #2
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("Server: client disconnected: " + net2con.connectioninfo);
 }
コード例 #3
0
 void network_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     remoteclientdirtyqueues.Remove(net2con.connectioninfo.Connection);
 }
コード例 #4
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine( "isserver: " + net2con.isserver );
     LogFile.WriteLine( "net2con: " + net2con );
     LogFile.WriteLine( "connectioninfo: " + net2con.connectioninfo );
     LogFile.WriteLine( "connection: " + net2con.connectioninfo.Connection );
     remoteclientdirtyqueues.Add( net2con.connectioninfo.Connection, new DirtyObjectQueueSingleClient( this, net2con.connectioninfo.Connection ) );
 }
コード例 #5
0
ファイル: TestLevel2.cs プロジェクト: hughperkins/osmp-cs
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: connected to server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
     net.Send( net2con.connectioninfo.Connection, 'Z', Encoding.UTF8.GetBytes("Hello server!") );
 }
コード例 #6
0
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Server: Client connected " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
コード例 #7
0
        public void ReceivedPacketHandler( ConnectionInfo connection, byte[]packet, int nextposition, int length )
        {
            //object connection = e.Connection;
            //byte[] packet = e.Data;
            //int nextposition = e.DataStartIndex;

            lasttimestamp = DateTime.Now;

            if( packet.Length >= 4 + 2 + 1 )
            {
                int packetkey = (int)binarypacker.ReadValueFromBuffer(packet, ref nextposition, typeof(int));
                short packetref = (short)binarypacker.ReadValueFromBuffer(packet, ref nextposition, typeof(short));
                char packetcode = (char)binarypacker.ReadValueFromBuffer(packet, ref nextposition, typeof(char));

                //LogFile.WriteLine( "Packet key: " + packetkey.ToString() + " packetref: " + packetref.ToString() + " packetcode: " + packetcode );

                if( unsafepackethandlers.Contains( packetcode ) )
                {
                    //LogFile.WriteLine("calling unsafepackethandler...");
                    if( packetreferencecontroller.ValidateIncomingReference( packetref ) )
                    {
                        //LogFile.WriteLine("Incoming reference validated");
                        ((PacketHandler)unsafepackethandlers[packetcode])(this, new PacketHandlerArgs(
                            packetkey, packetcode, packetref, packet, nextposition ) );
                    }
                }
                else
                {
                    if( sharedsecretexchange.ValidateIncomingPacketKey( packetkey ) )
                    {
                        if( packetreferencecontroller.ValidateIncomingReference( packetref ) )
                        {
                            if( packethandlers.Contains( packetcode ) )
                            {
                                ((PacketHandler)packethandlers[ packetcode ])( this, new PacketHandlerArgs(
                                    packetkey, packetcode, packetref, packet, nextposition ) );
                            }
                            else if (parent.packetconsumers.ContainsKey(packetcode))
                            {
                                parent.packetconsumers[packetcode](this, packet, nextposition, length - nextposition);
                            }
                            else
                            {
                                LogFile.WriteLine("Warning: unknown packet code " + packetcode.ToString() + " " + Encoding.ASCII.GetString(packet, 0, packet.Length));
                            }
                        }// else silently ignore duplicate packet
                    }
                    else
                    {
                        if (isserver)
                        {
                            LogFile.WriteLine("WARNING: server received potentially spoofed packet allegedly from " + connection.ToString() + " " + Encoding.ASCII.GetString(packet, 0, packet.Length));
                        }
                        else
                        {
                            LogFile.WriteLine("WARNING: client received potentially spoofed packet allegedly from " + connection.ToString() + " " + Encoding.ASCII.GetString(packet, 0, packet.Length));
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: stun.cs プロジェクト: hughperkins/osmp-cs
 void network_ReceivedPacket( INetworkImplementation source, ConnectionInfo connectioninfo, byte[] data, int offset, int length )
 {
     try
     {
         //LogFile.WriteLine("STUN network receivedpacket");
         if (length > 2 && data[0] == 1 && data[0] == 1) // bindingresponse
         {
             LogFile.WriteLine( this.GetType() + "could be binding reponse");
             Message responsemessage = Message.Decode(data, 0, data.Length);
             MappedAddressAttribute mappedaddress = (MappedAddressAttribute)responsemessage.GetAttribute( net.voxx.stun4cs.Attribute.MAPPED_ADDRESS );
             IPAddress ipaddress = new IPAddress( mappedaddress.GetAddressBytes() );
             int port = mappedaddress.GetAddress().GetPort();
             Console.WriteLine( ipaddress + " " + port );
             network.ReceivedPacket -= packethandler;
             callback( ipaddress, port );
         }
         else if (length > 2 && data[0] == 1 && data[0] == 0x11) // bindingerror response
         {
             LogFile.WriteLine( this.GetType() + " could be binding error");
         }
     }
     catch( Exception e )
     {
         //LogFile.WriteLine( "STUN networkreceivedpacket " + e);
     }
 }
コード例 #9
0
ファイル: TestNetRpc.cs プロジェクト: hughperkins/osmp-cs
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestNetRpcServer, new connection: " + net2con.connectioninfo);
 }
コード例 #10
0
ファイル: TestNetRpc.cs プロジェクト: hughperkins/osmp-cs
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("Testnetrpc , new connection " + connectioninfo);
     RpcController rpc = new RpcController(network);
     TestController.GetInstance().rpc = rpc;
     Testing.TestInterface_ClientProxy testinterface_clientproxy = new OSMP.Testing.TestInterface_ClientProxy(rpc, null);
     testinterface_clientproxy.SayHello();
 }
コード例 #11
0
ファイル: TestNetworkUdp.cs プロジェクト: hughperkins/osmp-cs
 void net_ReceivedPacket( INetworkImplementation source, ConnectionInfo connectioninfo, byte[] data, int offset, int length )
 {
     LogFile.WriteLine( "Received packet: " + Encoding.UTF8.GetString( data ) );
 }
コード例 #12
0
ファイル: TestNetworkUdp.cs プロジェクト: hughperkins/osmp-cs
 void net_ReceivedPacket( INetworkImplementation source, ConnectionInfo connectioninfo, byte[] data, int offset, int length )
 {
     LogFile.WriteLine("Received packet: " + Encoding.UTF8.GetString(data));
     net.Send(connectioninfo.Connection, Encoding.UTF8.GetBytes( "Hello from server!" ) );
 }
コード例 #13
0
 void network_NewConnection( NetworkLevel2Connection net2con, ConnectionInfo connectioninfo )
 {
     LogFile.WriteLine( "showserverdialog.network_newconnection()" );
     new STUN( net2con.networkimplementation, new STUN.GotExternalAddress( STUNResponseForOwnInterface ) );
 }
コード例 #14
0
 void net_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: Disconnected from server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
コード例 #15
0
 public Level1ConnectionInfo( IPEndPoint EndPoint, ConnectionInfo connectioninfo )
 {
     this.EndPoint = EndPoint;
     this.connectioninfo = connectioninfo;
     LastTimestamp = DateTime.Now;
     LastOutgoingPacketTime = DateTime.Now;
 }
コード例 #16
0
 void network_NewConnection( NetworkLevel2Connection net2con, ConnectionInfo connectioninfo )
 {
     LogFile.WriteLine( "showserverdialog.network_newconnection()" );
     new STUN( net2con.networkimplementation, new STUN.GotExternalAddress( STUNResponseForOwnInterface ) );
 }
コード例 #17
0
        public void ReceivedPacketHandler( INetworkImplementation source, ConnectionInfo connectioninfo, byte[] data, int offset, int length )
        {
            object connection = connectioninfo.Connection;

            //LogFile.WriteLine("Connection: "  + connection);
            if (IsServer)
            {
                if (!connections.ContainsKey(connection))
                {
                    NetworkLevel2Connection networklevel2connection = new NetworkLevel2Connection(this, connectioninfo, IsServer);
                    connections.Add(connection, networklevel2connection);
                }
                connections[connection].ReceivedPacketHandler(connectioninfo, data, offset, length);
            }
            else
            {
                connectiontoserver.ReceivedPacketHandler(connectioninfo, data, offset, length);
            }
        }
コード例 #18
0
        void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
        {
            LogFile.WriteLine("client connected to server");
            waitingforserverconnection = false;

            InitializePlayermovement();

            myavatar = new Avatar();
            worldstorage.AddEntity(myavatar);

            new NetworkInterfaces.WorldControl_ClientProxy(rpc, connectioninfo.Connection)
                .RequestResendWorld();
        }
コード例 #19
0
ファイル: TestLevel2.cs プロジェクト: hughperkins/osmp-cs
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Server: Client connected " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
コード例 #20
0
ファイル: TestLevel2.cs プロジェクト: hughperkins/osmp-cs
 void net_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: Disconnected from server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
コード例 #21
0
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: connected to server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
     net.Send(net2con.connectioninfo.Connection, 'Z', Encoding.UTF8.GetBytes("Hello server!"));
 }