muc_log.vala
changeset 12 d3e36b368fc5
parent 9 d3260253f0bd
equal deleted inserted replaced
11:0f0cf428409f 12:d3e36b368fc5
    33             for( var j = 0, iTop = s.length; j < iTop; j++ ) {
    33             for( var j = 0, iTop = s.length; j < iTop; j++ ) {
    34                 sum += k ^ s[j];
    34                 sum += k ^ s[j];
    35             }
    35             }
    36             return ((sum ^ m)+l)%10;
    36             return ((sum ^ m)+l)%10;
    37         }
    37         }
       
    38 
       
    39         protected void real_write(Time time, string _class, string nick, string str) {
       
    40             var id = getid(time);
       
    41             var times = time.format("%H:%M:%S");
       
    42             var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
       
    43 
       
    44             file.printf("<tr id='l_%s' class='%s'><td class='time'><a id='i_%s' href='#i_%s'>%s</a></td>", id, _class, id, id, times);
       
    45             file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
       
    46             file.flush();
       
    47         }
       
    48 
    38         public void write(Time time, string _class, string nick, string str) {
    49         public void write(Time time, string _class, string nick, string str) {
    39 
       
    40             if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
    50             if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
    41                 var fname = time.format(logpath).replace("<muc>",jid);
    51                 var fname = time.format(logpath).replace("<muc>",jid);
    42                 log("muc_log", LogLevelFlags.LEVEL_INFO, "Switching log file '%s' to '%s'", filename, fname);
    52                 log("muc_log", LogLevelFlags.LEVEL_INFO, "Switching log file '%s' to '%s'", filename, fname);
    43                 if (file!=null) file.flush();
    53                 bool wasntnull = false;
       
    54                 if (file!=null) {
       
    55                     wasntnull = true;
       
    56                     real_write(time, "logstop", "", "Log stopped. See you in the next episode.");
       
    57                 }
    44                 //try {
    58                 //try {
    45                     file = FileStream.open(fname,"a");
    59                     file = FileStream.open(fname,"a");
    46                 if (file==null) {
    60                 if (file==null) {
    47                     int start = 0;
    61                     int start = 0;
    48                     int length = fname.length;
    62                     int length = fname.length;
    77                         }
    91                         }
    78                     }
    92                     }
    79                 }
    93                 }
    80                 filename = fname;
    94                 filename = fname;
    81                 lastyear = time.year; lastmonth = time.month; lastday = time.day;
    95                 lastyear = time.year; lastmonth = time.month; lastday = time.day;
       
    96                 if (wasntnull)
       
    97                     real_write(time, "logstart", "", "Log started. This soap opera will never end.");
    82             }
    98             }
    83             
       
    84             var id = getid(time);
       
    85             var times = time.format("%H:%M:%S");
       
    86             var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
       
    87 
    99 
    88             file.printf("<tr id='l_%s' class='%s'><td class='time'><a id='i_%s' href='#i_%s'>%s</a></td>", id, _class, id, id, times);
   100             real_write(time, _class, nick, str);
    89             file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
       
    90             file.flush();
       
    91         }
   101         }
    92             
   102             
    93     }
   103     }
    94     public string getconf(string jid, string key, string? def) {
   104     public string getconf(string jid, string key, string? def) {
    95         var res = cfg["muc "+jid, key];
   105         var res = cfg["muc "+jid, key];