Esempio n. 1
0
        public NetSharedSecretExchange(NetworkLevel2Connection networkmodelconnection, bool isserver)
        {
            //LogFile.WriteLine("NetSharedSecretExchange()");
            this.parent   = networkmodelconnection;
            this.isserver = isserver;

            parent.RegisterUnsafePacketHandler('R', new PacketHandler(RPacketHandler));
            parent.RegisterUnsafePacketHandler('C', new PacketHandler(CPacketHandler));
            // parent.RegisterUnsafePacketHandler('D', new PacketHandler(DPacketHandler));

            if (rand == null)
            {
                rand = new MyRand((int)System.DateTime.Now.Ticks);
            }

            lastRpacket = new DateTime();

            if (isserver)
            {
                SharedSecretKey = GenerateSharedKey();
            }
            else
            {
                tempclientkey = rand.GetRandomInt(0, int.MaxValue - 1);
                //SendRPacketToServer();
            }
        }
Esempio n. 2
0
 public void OnPacketReceived(char packettype, NetworkLevel2Connection net2con, byte[] data, int offset, int length)
 {
     if (packetconsumers.ContainsKey(packettype))
     {
         packetconsumers[packettype](net2con, data, offset, length);
     }
 }
Esempio n. 3
0
 public void ListenAsServer(int port)
 {
     LogFile.WriteLine("NetworkController.  Listen as server port " + port);
     IsServer           = true;
     connectiontoserver = null;
     connections        = new Dictionary <object, NetworkLevel2Connection>();
     networkimplementation.ListenAsServer(port);
 }
Esempio n. 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));
 }
 public NetPacketReferenceController( NetworkLevel2Connection parent, bool isserver )
 {
     this.parent = parent;
     this.isserver = isserver;
     lastresendcheck = DateTime.Now;
     lastackpacketsent = DateTime.Now;
     parent.RegisterPacketHandler( 'A', new PacketHandler( APacketHandler ) );
 }
Esempio n. 6
0
        public Hashtable sentpacketsawaitingack = new Hashtable(); // ( packetref, new object[]{ datetime, byte[]packet ) )

        public NetPacketReferenceController(NetworkLevel2Connection parent, bool isserver)
        {
            this.parent       = parent;
            this.isserver     = isserver;
            lastresendcheck   = DateTime.Now;
            lastackpacketsent = DateTime.Now;
            parent.RegisterPacketHandler('A', new PacketHandler(APacketHandler));
        }
Esempio n. 7
0
 public void OnConnectionValidated(NetworkLevel2Connection netcon)
 {
     LogFile.WriteLine("Networklevel2controller new connection: " + netcon.connectioninfo.IPAddress + " " + netcon.connectioninfo.Port);
     if (NewConnection != null)
     {
         NewConnection(netcon, netcon.connectioninfo);
     }
 }
Esempio n. 8
0
            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();
            }
Esempio n. 9
0
        public void ConnectAsClient(string ipaddress, int port)
        {
            LogFile.WriteLine("NetworkController.  Connect as client to " + ipaddress + " " + port);
            IsServer    = false;
            connections = null;
//            connectionopen = false;
            connectiontoserver = new NetworkLevel2Connection(this, new ConnectionInfo(null, System.Net.IPAddress.Parse(ipaddress), port), false);
            networkimplementation.ConnectAsClient(ipaddress, port);
        }
Esempio n. 10
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();
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        void network_ReceivedPacket(NetworkLevel2Connection connection, byte[] data, int offset, int length)
        {
            //LogFile.WriteLine("rpc received packet " + Encoding.UTF8.GetString(data, offset, length));
            try
            {
                if (length > 1)
                {
                    int position = offset;
                    //char type = (char)binarypacker.ReadValueFromBuffer(data, ref position, typeof(Char));
                    //if (type == RpcType)
                    //{
                    string typename   = (string)binarypacker.ReadValueFromBuffer(data, ref position, typeof(string));
                    string methodname = (string)binarypacker.ReadValueFromBuffer(data, ref position, typeof(string));
                    //        LogFile.WriteLine("Got rpc [" + typename + "] [" + methodname + "]");
                    if (TypeIsAllowed(typename))        // security check to prevent arbitrary activation
                    //if (ArrayHelper.IsInArray(allowedtypes, typename))
                    {
                        int    dotpos        = typename.LastIndexOf(".");
                        string namespacename = "";
                        string interfacename;
                        if (dotpos >= 0)
                        {
                            namespacename = typename.Substring(0, dotpos);
                            interfacename = typename.Substring(dotpos + 1);
                        }
                        else
                        {
                            interfacename = typename;
                        }
                        //                LogFile.WriteLine("[" + namespacename + "][" + interfacename + "]");

                        string serverwrapperclassname = "OSMP." + interfacename.Substring(1) + "";
                        //              LogFile.WriteLine("serverwrapperclassname [" + serverwrapperclassname + "]");
                        //if (namespacename != "")
                        //{
                        //  serverwrapperclassname = namespacename + "." + serverwrapperclassname;
                        //}

                        Type interfacetype = Type.GetType(typename);

                        string typenametoinstantiate = serverwrapperclassname + ", " + TargetAssemblyName;
                        LogFile.WriteLine("typenametoinstantiate: [" + typenametoinstantiate + "]");
                        Type serverwrapperttype = Type.GetType(serverwrapperclassname + ", " + TargetAssemblyName);

                        if (isserver)
                        {
                            LogFile.WriteLine("server RpcController, instantiating [" + serverwrapperttype + "]");
                        }
                        else
                        {
                            LogFile.WriteLine("client RpcController, instantiating [" + serverwrapperttype + "]");
                        }
                        object     serverwrapperobject = Activator.CreateInstance(serverwrapperttype, new object[] { connection.connectioninfo.Connection });
                        MethodInfo methodinfo          = serverwrapperttype.GetMethod(methodname);

                        ParameterInfo[] parameterinfos = methodinfo.GetParameters();
                        object[]        parameters     = new object[parameterinfos.GetLength(0)];
                        for (int i = 0; i < parameters.GetLength(0); i++)
                        {
                            parameters[i] = binarypacker.ReadValueFromBuffer(data, ref position, parameterinfos[i].ParameterType);
                        }

                        //foreach (object parameter in parameters)
                        //{
                        //   LogFile.WriteLine(parameter.GetType().ToString() + " " + parameter.ToString());
                        //}
                        methodinfo.Invoke(serverwrapperobject, parameters);
                    }
                    else
                    {
                        LogFile.WriteLine("Warning: unauthorized RPC type " + typename + ". Check has attribute [AuthorizedRpcInterface]");
                    }
                    //}
                }
            }
            catch (Exception ex)
            {
                LogFile.WriteLine(ex);
            }
        }
Esempio n. 13
0
 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();
 }
Esempio n. 14
0
 void network_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     remoteclientdirtyqueues.Remove(net2con.connectioninfo.Connection);
 }
Esempio n. 15
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("Server: client disconnected: " + net2con.connectioninfo);
 }
Esempio n. 16
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();
        }
        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);
            }
        }
 public void ListenAsServer( int port )
 {
     LogFile.WriteLine("NetworkController.  Listen as server port " + port);
     IsServer = true;
     connectiontoserver = null;
     connections = new Dictionary<object,NetworkLevel2Connection>();
     networkimplementation.ListenAsServer( port );
 }
Esempio n. 19
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestNetRpcServer, new connection: " + net2con.connectioninfo);
 }
Esempio n. 20
0
 void net_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: Disconnected from server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
 public void OnConnectionValidated(NetworkLevel2Connection netcon)
 {
     LogFile.WriteLine("Networklevel2controller new connection: " + netcon.connectioninfo.IPAddress + " " + netcon.connectioninfo.Port);
     if (NewConnection != null)
     {
         NewConnection(netcon, netcon.connectioninfo);
     }
 }
Esempio n. 22
0
 void net_ReceivedPacket(NetworkLevel2Connection net2con, byte[] data, int offset, int length)
 {
     LogFile.WriteLine("TestLevel2Server Received packet: " + Encoding.UTF8.GetString(data, offset, length));
     net.Send(net2con.connectioninfo.Connection, 'Z', Encoding.UTF8.GetBytes("Hello from server"));
 }
Esempio n. 23
0
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Server: Client connected " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
Esempio n. 24
0
 void net_ReceivedPacket(NetworkLevel2Connection net2con, byte[] data, int offset, int length)
 {
     LogFile.WriteLine("TestLevel2Client Received packet: " + Encoding.UTF8.GetString(data, offset, length));
     net.Send(net2con.connectioninfo.Connection, 'Z', Encoding.UTF8.GetBytes("Test reply from client"));
 }
Esempio n. 25
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("Server: client disconnected: " + net2con.connectioninfo);
 }
 public void ConnectAsClient( string ipaddress, int port )
 {
     LogFile.WriteLine("NetworkController.  Connect as client to " + ipaddress + " " + port);
     IsServer = false;
     connections = null;
     //            connectionopen = false;
     connectiontoserver = new NetworkLevel2Connection( this, new ConnectionInfo(null, System.Net.IPAddress.Parse( ipaddress ), port ), false );
     networkimplementation.ConnectAsClient( ipaddress, port );
 }
Esempio n. 27
0
 void network_NewConnection( NetworkLevel2Connection net2con, ConnectionInfo connectioninfo )
 {
     LogFile.WriteLine( "showserverdialog.network_newconnection()" );
     new STUN( net2con.networkimplementation, new STUN.GotExternalAddress( STUNResponseForOwnInterface ) );
 }
Esempio n. 28
0
 void network_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestNetRpcServer, new connection: " + net2con.connectioninfo);
 }
Esempio n. 29
0
 void network_NewConnection( NetworkLevel2Connection net2con, ConnectionInfo connectioninfo )
 {
     LogFile.WriteLine( "showserverdialog.network_newconnection()" );
     new STUN( net2con.networkimplementation, new STUN.GotExternalAddress( STUNResponseForOwnInterface ) );
 }
Esempio n. 30
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 ) );
 }
Esempio n. 31
0
 void net_NewConnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Server: Client connected " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
 public void OnPacketReceived(char packettype, NetworkLevel2Connection net2con, byte[] data, int offset, int length )
 {
     if( packetconsumers.ContainsKey( packettype ) )
     {
         packetconsumers[ packettype ]( net2con, data, offset, length );
     }
 }
Esempio n. 33
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!") );
 }
Esempio n. 34
0
 void net_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     LogFile.WriteLine("TestLevel2Client: Disconnected from server " + connectioninfo.IPAddress.ToString() + " " + connectioninfo.Port);
 }
Esempio n. 35
0
 void network_Disconnection(NetworkLevel2Connection net2con, ConnectionInfo connectioninfo)
 {
     remoteclientdirtyqueues.Remove(net2con.connectioninfo.Connection);
 }
Esempio n. 36
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!"));
 }