//~~~~~~~~~~~~~~{Setter}~~~~~~~~~~~~~~ /// <summary>Merges two connections, grabbing the socket from this conneciton</summary> /// <param name="OtherConnection"></param> public void AbsorbConnection(SwitchboardConnection OtherConnection) { while (Busy) { } //Wait for *this* connection to not be busy TickThread.Abort(); //Stop the thread //Close this connection's river and socket River.Close(); TheSocket.Close(); //Move everything over River = OtherConnection.River; TheSocket = OtherConnection.TheSocket; IP = OtherConnection.IP; //Send OK Send("OK", false); //Start async again StartAsync(); //Log it HeadServer.ToLog("User from " + IP.Address.ToString() + " reconnected from " + OtherConnection.IP.Address.ToString()); //Remove the other connection from the list of connections HeadServer.Connections.Remove(OtherConnection.ID); //Look at how far back we can go HeadServer.TheForm.ServerBWorker.ReportProgress(0); //Refresh the main form's listview. //Stop the other tickthread. This will stop *this* operation, so it's the last one to go. OtherConnection.TickThread.Abort(); }
//~~~~~~~~~~~~~~{Constructor}~~~~~~~~~~~~~~ public SwitchboardConnection(SwitchboardServer HeadServer, Socket MainSocket, int ID) { this.ID = ID; ConnectedSince = DateTime.Now; IP = (IPEndPoint)MainSocket.RemoteEndPoint; River = new NetworkStream(MainSocket); TheSocket = MainSocket; this.HeadServer = HeadServer; HeadServer.ToLog("New user connected from " + IP.Address.ToString()); User = HeadServer.AnonymousUser; ConsolePreview = ""; }