# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


import os
import copy
import signal
import time
import User
import UserManager
import Config
import MsgBox
import MsgHead
import modes
import Utmp
from Log import Log

        if (not from_user.CanSee(to_userinfo)):
#                and sender_mode != modes.CHAT1):
            return -2

        if (to_userinfo.mode == modes.LOCKSCREEN and sender_mode != 3):
            return -1

        if (from_user.BeIgnored(to_userid) and sender_mode != 3):
            return -11

        to_msgbox = MsgBox.MsgBox(to_userid)
        if (to_userinfo.mode != modes.WEBEXPLORE and sender_mode != 3):
            if (to_msgbox.GetUnreadCount() > Config.MAXMESSAGE):
                return -12;

        # to_userinfo is readonly
        # and I don't want to generate a new one...
        to_login = to_userinfo.GetIndex()
        pid = Utmp.Utmp.GetPid(to_login - 1)
        active = Utmp.Utmp.IsActive(to_login - 1)
        userid = Utmp.Utmp.GetUserId(to_login - 1)

        if (active == 0 or pid == 0 or userid != to_userid):
            Log.debug("error -14: %d %d" % (active, pid))
            return -14;

        try:
            os.kill(pid, 0)
        except OSError:

# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


# Path: Msg.py
import os
import copy
import signal
import time
import User
import UserManager
import Config
import MsgBox
import MsgHead
import modes
import Utmp
from Log import Log


        if (not from_user.CanSee(to_userinfo)):
#                and sender_mode != modes.CHAT1):
            return -2

        if (to_userinfo.mode == modes.LOCKSCREEN and sender_mode != 3):
            return -1

        if (from_user.BeIgnored(to_userid) and sender_mode != 3):
            return -11

        to_msgbox = MsgBox.MsgBox(to_userid)
        if (to_userinfo.mode != modes.WEBEXPLORE and sender_mode != 3):
            if (to_msgbox.GetUnreadCount() > Config.MAXMESSAGE):
                return -12;

        # to_userinfo is readonly
        # and I don't want to generate a new one...
        to_login = to_userinfo.GetIndex()
        pid = Utmp.Utmp.GetPid(to_login - 1)
        active = Utmp.Utmp.IsActive(to_login - 1)
        userid = Utmp.Utmp.GetUserId(to_login - 1)

        if (active == 0 or pid == 0 or userid != to_userid):
            Log.debug("error -14: %d %d" % (active, pid))
            return -14;

        try:
            os.kill(pid, 0)
        except OSError:

            Log.debug("error -14: kill fail, process gone")