Esempio n. 1
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            LiteCodeClient Client = OpSocket as LiteCodeClient;

            lock (Client.InitializedClasses)
            {
                if (Client.InitializedClasses.ContainsKey(SharedClassId))
                {
                    Client.InitializedClasses[SharedClassId].IsDisposed = true;

                    SharedClass localSharedClass = null;
                    lock (Client.SharedClasses)
                    {
                        if (Client.SharedClasses.TryGetValue(Client.InitializedClasses[SharedClassId].SharedName, out localSharedClass))
                        {
                            localSharedClass.SharedInitializeCounter--;
                        }
                    }

                    Client.InitializedClasses[SharedClassId] = null;
                    Client.InitializedClasses.Remove(SharedClassId);
                }
                else
                {
                    //strange client behavior
                    Client.Disconnect();
                }
            }
        }
 public Header DeserializeHeader(OperationalSocket OpSocket)
 {
     Type HeaderType = OpSocket.Headers.GetHeaderType(HeaderPayloadId);
     if(HeaderType == null)
         return null;
     return Headers.Header.DeSerialize(HeaderType, new Utils.PayloadReader(HeaderPayload));
 }
Esempio n. 3
0
 internal bool RegisteredOperationalSocket(OperationalSocket opSocket)
 {
     lock (Connection.RegisteredOperationalSockets)
     {
         return(Connection.RegisteredOperationalSockets.ContainsKey(opSocket.GetIdentifier()));
     }
 }
Esempio n. 4
0
 public SystemPacket(Header header, IMessage message, ushort ConnectionId, OperationalSocket OpSocket)
 {
     this.Header       = header;
     this.Message      = message;
     this.ConnectionId = ConnectionId;
     this.OpSocket     = OpSocket;
 }
        public ConnectionHeader(Header header, OperationalSocket OpSocket, int FeatureId)
            : base()
        {
            this.HeaderPayload = Headers.Header.Serialize(header);

            this.HeaderPayloadId = OpSocket.Headers.GetHeaderId(header);
            this.FeatureId       = FeatureId;
        }
        public ConnectionHeader(Header header, OperationalSocket OpSocket, int FeatureId)
            : base()
        {
            this.HeaderPayload = Headers.Header.Serialize(header);

            this.HeaderPayloadId = OpSocket.Headers.GetHeaderId(header);
            this.FeatureId = FeatureId;
        }
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     RequestHeader reqHeader = Header as RequestHeader;
     if (reqHeader != null)
     {
         reqHeader.HandleResponse(client, Number);
     }
 }
Esempio n. 8
0
 public override void onOperationalSocket_BeforeConnect(OperationalSocket OPSocket)
 {
     if (OPSocket as LiteCodeClient != null)
     {
         LiteCodeClient liteClient = OPSocket as LiteCodeClient;
         liteClient.ShareClass("SharedTest", typeof(SharedTest), false, int.MaxValue); //int.MaxValue = BAD, use 5-10 instead
     }
 }
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;

            if (reqHeader != null)
            {
                reqHeader.HandleResponse(client, Number);
            }
        }
Esempio n. 10
0
 public OptimizedPayloadStream(byte[] SerializedHeader, ushort HeaderId,
                               Feature feature = null, OperationalSocket OpSocket = null)
     : base()
 {
     this.PayloadFrames    = new List <MemoryStream>();
     this.SerializedHeader = SerializedHeader;
     this.HeaderId         = HeaderId;
     this.feature          = feature;
     this.OpSocket         = OpSocket;
 }
        public Header DeserializeHeader(OperationalSocket OpSocket)
        {
            Type HeaderType = OpSocket.Headers.GetHeaderType(HeaderPayloadId);

            if (HeaderType == null)
            {
                return(null);
            }
            return(Headers.Header.DeSerialize(HeaderType, new Utils.PayloadReader(HeaderPayload)));
        }
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     RequestHeader ReqHeader = Header as RequestHeader;
     if (ReqHeader != null)
     {
         if (client.IsServerSided)
         {
             client.Connection.SendMessage(new MsgGetNextIdResponse(client.Server.randomDecimal.NextDecimal()), new RequestHeader(ReqHeader.RequestId, true));
         }
     }
 }
Esempio n. 13
0
 public void RegisterOperationalSocket(OperationalSocket opSocket)
 {
     lock (Connection.RegisteredOperationalSockets)
     {
         if (Connection.RegisteredOperationalSockets.ContainsKey(opSocket.GetIdentifier()))
         {
             throw new Exception("This operational socket is already registered, conflict?");
         }
         Connection.RegisteredOperationalSockets.Add(opSocket.GetIdentifier(), opSocket.GetType());
     }
 }
Esempio n. 14
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader ReqHeader = Header as RequestHeader;

            if (ReqHeader != null)
            {
                if (client.IsServerSided)
                {
                    client.Connection.SendMessage(new MsgGetNextIdResponse(client.Server.randomDecimal.NextDecimal()), new RequestHeader(ReqHeader.RequestId, true));
                }
            }
        }
Esempio n. 15
0
 public SyncObject(OperationalSocket OpSocket)
 {
     if (OpSocket == null)
     {
         throw new ArgumentNullException("OpSocket");
     }
     if (OpSocket.Client == null)
     {
         throw new ArgumentNullException("OpSocket.Client");
     }
     this.connection = OpSocket.Client.Connection;
 }
Esempio n. 16
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;

            if (reqHeader != null)
            {
                lock (client.Connection.OperationalSockets)
                {
                    if (!client.Connection.OperationalSockets.TryGetValue(ConnectionId, out OpSocket))
                    {
                        return;
                    }
                }


                if (!OpSocket.isConnected)
                {
                    return;
                }

                OpSocket.InternalSendMessage(new MsgOpDisconnectResponse(ConnectionId), new RequestHeader(reqHeader.RequestId, true));
                OpSocket.isConnected = false;

                lock (client.Connection.OperationalSockets)
                {
                    if (client.Connection.OperationalSockets.ContainsKey(OpSocket.ConnectionId))
                    {
                        client.Connection.OperationalSockets.Remove(OpSocket.ConnectionId);
                    }
                }

                try
                {
                    OpSocket.onDisconnect(DisconnectReason.UserDisconnection);
                    client.onOperationalSocket_Disconnected(OpSocket, DisconnectReason.UserDisconnection);
                }
                catch (Exception ex)
                {
                    SysLogger.Log(ex.Message, SysLogType.Error);
                }
            }
        }
Esempio n. 17
0
 public abstract void onOperationalSocket_Disconnected(OperationalSocket OPSocket, DisconnectReason Reason);
Esempio n. 18
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            ReturnResult   result = new ReturnResult(null, false);
            LiteCodeClient Client = OpSocket as LiteCodeClient;

            try
            {
                PayloadReader pr     = new PayloadReader(Data);
                SharedClass   sClass = null;

                if (Client.InitializedClasses.TryGetValue(SharedClassId, out sClass))
                {
                    SharedMethod sharedMethod = sClass.GetMethod(MethodId);

                    if (sharedMethod != null)
                    {
                        List <object> args  = new List <object>();
                        List <Type>   types = new List <Type>();
                        SortedList <int, SharedDelegate> SharedDelegates = new SortedList <int, SharedDelegate>();
                        SmartSerializer serializer = new SmartSerializer();

                        lock (sharedMethod.Delegates)
                        {
                            SharedDelegate sharedDel = null;
                            if (sharedMethod.Delegates.TryGetValue(DelegateId, out sharedDel))
                            {
                                for (int i = 0; i < sharedDel.sharedMethod.ArgumentTypes.Length; i++)
                                {
                                    args.Add(serializer.Deserialize(pr.ReadBytes(pr.ReadInteger())));
                                }
                            }
                            else
                            {
                                for (int i = 0; i < sharedMethod.ArgumentTypes.Length; i++)
                                {
                                    args.Add(serializer.Deserialize(pr.ReadBytes(pr.ReadInteger())));
                                }
                            }
                        }

                        if (!isDelegate) //atm no support yet for delegate inside another delegate
                        {
                            for (int i = 0; i < sharedMethod.DelegateIndex.Count; i++)
                            {
                                if (pr.ReadByte() == 1)
                                {
                                    SharedDelegate del = pr.ReadObject <SharedDelegate>();
                                    del.sharedMethod.sharedClass             = sClass;
                                    args[sharedMethod.DelegateIndex.Keys[i]] = DynamicDelegateCreator.CreateDelegate(del);
                                    SharedDelegates.Add(del.sharedMethod.DelegateId, del);
                                }
                            }
                        }

                        if (isDelegate)
                        {
                            result.ReturnValue = sharedMethod.Delegates[DelegateId].Delegate.DynamicInvoke(args.ToArray());
                        }
                        else
                        {
                            if (sharedMethod.CallCache == null)
                            {
                                MethodInfo methodInf = sClass.InitializedClass.GetType().GetMethod(sharedMethod.Name, sharedMethod.ArgumentTypes);
                                sharedMethod.CallCache = methodInf.Bind();
                            }
                            result.ReturnValue = sharedMethod.CallCache(sClass.InitializedClass, args.ToArray());

                            /*MethodInfo methodInf = sClass.InitializedClass.GetType().GetMethod(sharedMethod.Name, sharedMethod.ArgumentTypes);
                             * result.ReturnValue = methodInf.Invoke(sClass.InitializedClass, args.ToArray());*/
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.exceptionMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                result.ExceptionOccured = true;
                client.onException(ex.InnerException != null ? ex.InnerException : ex, ErrorType.UserLand);
            }

            if (RequireResultBack)
            {
                Client.Send(new MsgExecuteMethodResponse(RequestId, result));
            }
        }
Esempio n. 19
0
 public override void onOperationalSocket_Disconnected(OperationalSocket OPSocket, DisconnectReason Reason)
 {
 }
Esempio n. 20
0
 public override void onOperationalSocket_BeforeConnect(OperationalSocket OPSocket)
 {
 }
Esempio n. 21
0
 public override void onOperationalSocket_Connected(OperationalSocket OPSocket)
 {
 }
Esempio n. 22
0
 public abstract void ProcessPayload(SSPClient client, OperationalSocket OpSocket);
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
 }
Esempio n. 24
0
 public abstract void ProcessPayload(SSPClient client, OperationalSocket OpSocket);
Esempio n. 25
0
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
 }
Esempio n. 26
0
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     client.Connection.InitSync.Value = true;
     client.Connection.InitSync.Pulse();
 }
Esempio n. 27
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            SSPClient _client = client as SSPClient;

            if (_client != null)
            {
                byte[]        responseData  = new byte[0];
                MazeErrorCode errorCode     = MazeErrorCode.Error;
                Mazing        mazeHandshake = _client.IsServerSided ? _client.serverHS : _client.clientHS;

                if (mazeHandshake == null)
                {
                    //error could occur on a unexpected disconnect
                    client.Connection.HandShakeCompleted = false;
                    client.Connection.HandshakeSync.Pulse();
                    return;
                }

                errorCode = mazeHandshake.onReceiveData(Data, ref responseData);


                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success && client.TimingConfiguration.Enable_Timing)
                {
                    //something went wrong, annoy the attacker
                    Thread.Sleep(client.TimingConfiguration.Authentication_WrongPassword);
                }

                if (responseData.Length > 0)
                {
                    client.Connection.SendMessage(new MsgHandshake(responseData), new SystemHeader());
                }

                if (client == null || client.Connection == null || client.Connection.HandshakeSync == null)
                {
                    //error could occur on a unexpected disconnect
                    return;
                }

                client.Connection.HandshakeSync.Value = errorCode;
                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success)
                {
                    client.Connection.HandshakeSync.Pulse();
                }
                else if (errorCode == MazeErrorCode.Finished)
                {
                    //let's tell it's completed and apply the new key
                    client.Connection.ApplyNewKey(mazeHandshake, mazeHandshake.FinalKey, mazeHandshake.FinalSalt);

                    if (_client.IsServerSided)
                    {
                        if (mazeHandshake as ServerMaze != null)
                        {
                            client.Username = (mazeHandshake as ServerMaze).Username;
                        }

                        client.Connection.HandShakeCompleted = true;

                        /*try
                         * {
                         *  client.onBeforeConnect();
                         * }
                         * catch (Exception ex)
                         * {
                         *  SysLogger.Log(ex.Message, SysLogType.Error);
                         *  client.onException(ex, ErrorType.UserLand);
                         *  return; //don't send that we're ready since we're clearly not at this point
                         * }*/

                        client.Connection.SendMessage(new MsgInitOk(), new SystemHeader());

                        try
                        {
                            client.onConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }
                    }
                    else
                    {
                        client.Connection.HandShakeCompleted = true;
                        client.Connection.HandshakeSync.Pulse();
                    }
                }
            }
        }
Esempio n. 28
0
 public abstract void onOperationalSocket_BeforeConnect(OperationalSocket OPSocket);
Esempio n. 29
0
 public abstract void onOperationalSocket_Connected(OperationalSocket OPSocket);
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            SSPClient _client = client as SSPClient;
            if (_client != null)
            {
                byte[] responseData = new byte[0];
                MazeErrorCode errorCode = MazeErrorCode.Error;
                Mazing mazeHandshake = _client.IsServerSided ? _client.serverHS : _client.clientHS;

                if (mazeHandshake == null)
                {
                    //error could occur on a unexpected disconnect
                    client.Connection.HandShakeCompleted = false;
                    client.Connection.HandshakeSync.Pulse();
                    return;
                }

                errorCode = mazeHandshake.onReceiveData(Data, ref responseData);

                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success && client.TimingConfiguration.Enable_Timing)
                {
                    //something went wrong, annoy the attacker
                    Thread.Sleep(client.TimingConfiguration.Authentication_WrongPassword);
                }

                if (responseData.Length > 0)
                {
                    client.Connection.SendMessage(new MsgHandshake(responseData), new SystemHeader());
                }

                if(client == null || client.Connection == null || client.Connection.HandshakeSync == null)
                {
                    //error could occur on a unexpected disconnect
                    return;
                }

                client.Connection.HandshakeSync.Value = errorCode;
                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success)
                {
                    client.Connection.HandshakeSync.Pulse();
                }
                else if (errorCode == MazeErrorCode.Finished)
                {
                    //let's tell it's completed and apply the new key
                    client.Connection.ApplyNewKey(mazeHandshake, mazeHandshake.FinalKey, mazeHandshake.FinalSalt);

                    if (_client.IsServerSided)
                    {
                        if (mazeHandshake as ServerMaze != null)
                        {
                            client.Username = (mazeHandshake as ServerMaze).Username;
                        }

                        client.Connection.HandShakeCompleted = true;

                        /*try
                        {
                            client.onBeforeConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }*/

                        client.Connection.SendMessage(new MsgInitOk(), new SystemHeader());

                        try
                        {
                            client.onConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }
                    }
                    else
                    {
                        client.Connection.HandShakeCompleted = true;
                        client.Connection.HandshakeSync.Pulse();
                    }
                }
            }
        }
Esempio n. 31
0
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     client.Connection.InitSync.Value = true;
     client.Connection.InitSync.Pulse();
 }
Esempio n. 32
0
 public override void ProcessPayload(SecureSocketProtocol3.SSPClient client, OperationalSocket OpSocket)
 {
 }
        public override void ProcessPayload(SSPClient client, OperationalSocket _OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;
            if (reqHeader != null)
            {
                Type type = null;
                lock (client.Connection.RegisteredOperationalSockets)
                {
                    client.Connection.RegisteredOperationalSockets.TryGetValue(Identifier, out type);
                }

                if(type != null)
                {
                    bool SendedSuccess = false;
                    try
                    {
                        OperationalSocket OpSocket = (OperationalSocket)Activator.CreateInstance(type, client);

                        OpSocket.isConnected = true;

                        lock (client.Connection.OperationalSockets)
                        {
                            FastRandom rnd = new FastRandom();
                            OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);
                            while(client.Connection.OperationalSockets.ContainsKey(OpSocket.ConnectionId))
                                OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);

                            client.Connection.OperationalSockets.Add(OpSocket.ConnectionId, OpSocket);
                        }

                        try
                        {
                            OpSocket.onBeforeConnect();
                            client.onOperationalSocket_BeforeConnect(OpSocket);
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            OpSocket.onException(ex, ErrorType.UserLand);
                        }

                        client.Connection.SendMessage(new MsgCreateConnectionResponse(OpSocket.ConnectionId, true), new RequestHeader(reqHeader.RequestId, true));
                        SendedSuccess = true;
                        OpSocket.onConnect();
                        client.onOperationalSocket_Connected(OpSocket);
                    }
                    catch (Exception ex)
                    {
                        SysLogger.Log(ex.Message, SysLogType.Error);

                        if (!SendedSuccess)
                        {
                            client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                        }
                    }
                }
                else
                {
                    client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                }
            }
        }
        public override void ProcessPayload(SSPClient client, OperationalSocket _OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;

            if (reqHeader != null)
            {
                Type type = null;
                lock (client.Connection.RegisteredOperationalSockets)
                {
                    client.Connection.RegisteredOperationalSockets.TryGetValue(Identifier, out type);
                }

                if (type != null)
                {
                    bool SendedSuccess = false;
                    try
                    {
                        OperationalSocket OpSocket = (OperationalSocket)Activator.CreateInstance(type, client);

                        OpSocket.isConnected = true;

                        lock (client.Connection.OperationalSockets)
                        {
                            FastRandom rnd = new FastRandom();
                            OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);
                            while (client.Connection.OperationalSockets.ContainsKey(OpSocket.ConnectionId))
                            {
                                OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);
                            }

                            client.Connection.OperationalSockets.Add(OpSocket.ConnectionId, OpSocket);
                        }


                        try
                        {
                            OpSocket.onBeforeConnect();
                            client.onOperationalSocket_BeforeConnect(OpSocket);
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            OpSocket.onException(ex, ErrorType.UserLand);
                        }

                        client.Connection.SendMessage(new MsgCreateConnectionResponse(OpSocket.ConnectionId, true), new RequestHeader(reqHeader.RequestId, true));
                        SendedSuccess = true;
                        OpSocket.onConnect();
                        client.onOperationalSocket_Connected(OpSocket);
                    }
                    catch (Exception ex)
                    {
                        SysLogger.Log(ex.Message, SysLogType.Error);

                        if (!SendedSuccess)
                        {
                            client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                        }
                    }
                }
                else
                {
                    client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                }
            }
        }