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); } }
public SEA3DEncoder(SID sid) : base(sid) { FileFormat = Data.ReadUTF8(); byte[] buffer = Data.ReadDataObject().ToArray(); buffer = Compression.Decompress(buffer, CompressionAlgorithm.Lzma); FileData = new ByteArray(buffer); }
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); } }
public SessionID(SID sid) : base(sid) { Properties.ReadJson(Data.ReadUTF32()); }
public Session(SID sid) { SID = sid; Data = SID.Data; }
public void OnConnect(SID sid) { sid.OnComplete += OnSIDComplete; sid.OnDisconnect += OnSIDDisconnect; }
public void OnSIDDisconnect(SID sid) { }
private void OnClientDisconnect(SID session) { Socket socket = session.Socket; Clientes.Remove(socket); SIDs.Remove(socket); }