Exemple #1
0
        public ConnectionContextResponse Write(WriteRequest request)
        {
            var response = new ConnectionContextResponse();
            var session  = CheckSession(ref request, ref response);

            if (session == null)
            {
                return(response);
            }

            var connection = session.CheckConnection(ref request, ref response);

            if (connection == null)
            {
                return(response);
            }

            try
            {
                var result = request.Data;
                Program.StaticXorEncoder(ref result, request.Cid);
                connection.Stream.Write(result, 0, result.Length);
                response.Success       = true;
                response.Message       = string.Empty;
                connection.WriteCount += result.Length;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = Strings.SERVER_SIDE + ex.Message;
            }

            return(response);
        }
Exemple #2
0
        public ConnectionContextResponse Disconnect(ConnectionContextRequest request)
        {
            var response = new ConnectionContextResponse();
            var session  = CheckSession(ref request, ref response);

            if (session != null)
            {
                var connection = session.CheckConnection(ref request, ref response);
                if (connection != null)
                {
                    try
                    {
                        response.Message = Strings.SERVER_SIDE + string.Format(Strings.DISCONNECTED, connection.TcpClient.Client.RemoteEndPoint);

                        connection.SafeDisconnect();
                        response.Connected     = false;
                        response.DataAvailable = false;
                        response.Success       = true;
                        session.RemoveConnection(request.Cid);
                    }
                    catch (Exception ex)
                    {
                        response.Success = false;
                        response.Message = Strings.SERVER_SIDE + ex.Message;
                    }
                }
            }

            Log(response.Message, ESeverity.INFO);
            return(response);
        }
Exemple #3
0
        public ConnectionContextResponse KillConnection(KillConnectionRequest request)
        {
            var response      = new ConnectionContextResponse();
            var targetsession = CheckSession(ref request, ref response);

            if (targetsession != null)
            {
                var targetconnection = targetsession.CheckConnection(ref request, ref response);
                if (targetconnection != null)
                {
                    var fake         = new SessionContextRequest(request.AdminSid);
                    var adminsession = CheckSession(ref fake, ref response);
                    if (adminsession != null)
                    {
                        if (adminsession.Admin)
                        {
                            try
                            {
                                response.Message = Strings.SERVER_SIDE +
                                                   string.Format(Strings.CONNECTION_KILLED, targetconnection.TcpClient.Client.RemoteEndPoint, targetsession.Username,
                                                                 adminsession.Username);

                                targetconnection.SafeDisconnect();
                                response.Connected     = false;
                                response.DataAvailable = false;
                                response.Success       = true;
                                targetsession.RemoveConnection(request.Cid);
                            }
                            catch (Exception ex)
                            {
                                response.Success = false;
                                response.Message = Strings.SERVER_SIDE + ex.Message;
                            }
                        }
                        else
                        {
                            response.Success = false;
                            response.Message = Strings.SERVER_SIDE + Strings.ADMIN_REQUIRED;
                        }
                    }
                }
            }

            Log(response.Message, ESeverity.INFO);
            return(response);
        }