Esempio n. 1
0
        private void OnClientConnect(IAsyncResult asyn)
        {
            try
            {
                Socket workSocket = mainSocket.EndAccept(asyn);
                try
                {
                    SID sid = new SID(workSocket);

                    sid.OnDisconnect += OnClientDisconnect;

                    if (OnConnect != null)
                        OnConnect(sid);

                    lock (this)
                    {
                        Clientes.Add(workSocket);
                        SIDs.Add(workSocket, sid);
                    }

                    mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
                }
                catch (SocketException se)
                {
                    if (OnError != null)
                        OnError(se.Message, workSocket, se.ErrorCode);
                }
            }
            catch (ObjectDisposedException se)
            {
                if (OnError != null)
                    OnError(se.Message, null, 0);
            }
        }
Esempio n. 2
0
        public SEA3DEncoder(SID sid)
            : base(sid)
        {
            FileFormat = Data.ReadUTF8();

            byte[] buffer = Data.ReadDataObject().ToArray();
            buffer = Compression.Decompress(buffer, CompressionAlgorithm.Lzma);

            FileData = new ByteArray(buffer);
        }
Esempio n. 3
0
        public void OnSIDComplete(SID sid)
        {
            try
            {
                if (sid.Length == POLICY_REQUEST.Length && sid.ReadUTF() == POLICY_REQUEST)
                {
                    sid.Send(POLICY_FILE);
                }
                else
                {
                    Session caller = null;

                    string callerType = sid.Data.ReadUTF8();

                    if (sid.ID != null)
                    {
                        if (Caller.ContainsKey(callerType))
                        {
                            ConstructorInfo constructorInfo = Caller[callerType].GetConstructor(new Type[1] { typeof(SID) });
                            caller = (Session)constructorInfo.Invoke(new object[1] { sid });
                        }

                        if (OnCaller != null)
                            OnCaller(caller);
                    }
                    else if (callerType == SessionID.Type)
                    {
                        caller = sid.ID = new SessionID(sid);

                        if (OnLogin != null)
                            OnLogin(sid.ID);
                    }
                    else
                    {
                        Console.WriteLine("Caller not found \"" + callerType + "\"");
                    }

                    if (caller != null)
                    {
                        ByteArray data = new ByteArray();
                        data.WriteDataObject(caller.Run());

                        sid.Send(data);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 4
0
 public SessionID(SID sid)
     : base(sid)
 {
     Properties.ReadJson(Data.ReadUTF32());
 }
Esempio n. 5
0
 public Session(SID sid)
 {
     SID = sid;
     Data = SID.Data;
 }
Esempio n. 6
0
 public void OnConnect(SID sid)
 {
     sid.OnComplete += OnSIDComplete;
     sid.OnDisconnect += OnSIDDisconnect;
 }
Esempio n. 7
0
 public void OnSIDDisconnect(SID sid)
 {
 }
Esempio n. 8
0
        private void OnClientDisconnect(SID session)
        {
            Socket socket = session.Socket;

            Clientes.Remove(socket);
            SIDs.Remove(socket);
        }