public void LogInvite(string inviteMethod, Dictionary <string, object> customAttributes = null) { var answersEvent = new InviteEvent(); answersEvent.PutMethod(inviteMethod); answersEvent.PutCustomAttributes(customAttributes); Bindings.AnswersKit.Answers.Instance.LogInvite(answersEvent); }
public static void ImportLogs(string characterName) { var characterPath = Path.Combine(App.DataDirectory, characterName); var slimcatPath = Path.Combine(slimCatRoaming, characterName); var eventSerializerSettings = new JsonSerializerSettings { Converters = new JsonConverter[] { new LogManager.CharacterConverter(null), new LogManager.ChannelMemberConverter(null), new LogManager.ChannelConverter() }, TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = new LogManager.EventSerializationBinder() }; var serializer = new MessageSerializer(null); foreach (var dir in Directory.EnumerateDirectories(slimcatPath)) { var name = Path.GetFileName(dir); var files = Directory.GetFiles(dir, "*.txt").Select(x => { try { var date = Path.GetFileNameWithoutExtension(x).Split('-').Select(int.Parse).ToArray(); return(new { Name = x, Date = new DateTime(date[2], date[0], date[1]) }); } catch { return(null); } }).Where(x => x != null).OrderBy(x => x.Date); if (name == "!Notifications") { var events = new StreamWriter(Path.Combine(characterPath, "EventLog")); foreach (var file in files) { foreach (var line in GetLogEntries(File.ReadLines(file.Name), eventRegex)) { try { Match match; Event e = null; DateTime GetTime() { var time = match.Groups[1].Value; return(file.Date.AddMinutes(int.Parse(time.Substring(0, 2)) * 60 + int.Parse(time.Substring(3)))); } if ((match = statusRegex.Match(line)).Success) { var status = match.Groups[4].Success ? match.Groups[4].Value.ToEnum <StatusEnum>() : StatusEnum.Online; e = new StatusEvent(new Character(match.Groups[2].Value), status, match.Groups[6].Value, GetTime()); } else if ((match = loginRegex.Match(line)).Success) { e = new LoginEvent(new Character(match.Groups[2].Value), GetTime()); } else if ((match = logoutRegex.Match(line)).Success) { e = new LogoutEvent(new Character(match.Groups[2].Value), GetTime()); } else if ((match = joinRegex.Match(line)).Success) { e = new ChannelJoinEvent(new Channel(null, match.Groups[3].Value, null), new Channel.Member(new Character(match.Groups[2].Value)), GetTime()); } else if ((match = leaveRegex.Match(line)).Success) { e = new ChannelLeaveEvent(new Channel(null, match.Groups[3].Value, null), new Channel.Member(new Character(match.Groups[2].Value)), GetTime()); } else if ((match = descriptionRegex.Match(line)).Success) { continue; } else if ((match = opChangeRegex.Match(line)).Success) { continue; } else if ((match = openRegex.Match(line)).Success) { continue; } else if ((match = listRegex.Match(line)).Success) { continue; } else if ((match = friendRegex.Match(line)).Success) { continue; } else if ((match = kickRegex.Match(line)).Success) { continue; } else if ((match = noteRegex.Match(line)).Success) { e = new NoteEvent(new Character(match.Groups[2].Value), null, match.Groups[3].Value, GetTime()); } else if ((match = broadcastRegex.Match(line)).Success) { e = new BroadcastEvent(new Character(match.Groups[2].Value), match.Groups[3].Value, GetTime()); } else if ((match = mentionRegex.Match(line)).Success) { var time = GetTime(); e = new MentionEvent(new Channel(null, match.Groups[4].Value, null), new Message(Message.Type.Message, new Character(match.Groups[2].Value), time, match.Groups[5].Value), GetTime()); } else if ((match = inviteRegex.Match(line)).Success) { e = new InviteEvent(new Character(match.Groups[2].Value), new ChannelListItem(match.Groups[4].Value, match.Groups[3].Value, 0), GetTime()); } if (e != null) { events.WriteLine(JsonConvert.SerializeObject(e, typeof(Event), Formatting.None, eventSerializerSettings)); } } catch {} } } events.Dispose(); continue; } Stream logs = null, ads = null, logsIndex = null, adsIndex = null; var parenIndex = name.IndexOf('('); var logDir = Path.Combine(characterPath, parenIndex != -1 ? $"#{name.Substring(parenIndex + 1, name.Length - parenIndex - 2)}" : officialChannels.Contains(name) ? $"#{name}" : name); if (Directory.Exists(logDir)) { continue; } Directory.CreateDirectory(logDir); foreach (var file in files) { var logsIndexed = false; var adsIndexed = false; foreach (var line in GetLogEntries(File.ReadLines(file.Name), logRegex)) { try { var index = 0; var type = Message.Type.Message; string sender; if (line.StartsWith("Ad at")) { type = Message.Type.Ad; index += 6; } var h = int.Parse(line.Substring(index + 1, 2)); var m = int.Parse(line.Substring(index + 4, 2)); index += 8; var text = ""; if (type == Message.Type.Ad) { var end = line.LastIndexOf("~By "); if (end != -1) { text = line.Substring(index, end - index); sender = line.Substring(end + 4); } else { sender = characterRegex.Match(line, index, Math.Min(20, line.Length - index)).Groups[1].Value; index += sender.Length; text = index < line.Length ? line.Substring(index) : ""; } } else { if (line[index] == '[') { type = Message.Type.Roll; var end = line.IndexOf('[', index); sender = line.Substring(index, end - index); } else { if (index + characterName.Length <= line.Length && line.Substring(index, characterName.Length) == characterName) { sender = characterName; } else if (index + name.Length <= line.Length && line.Substring(index, name.Length) == name) { sender = name; } else { sender = characterRegex.Match(line, index, Math.Min(20, line.Length - index)).Groups[1].Value; } index += sender.Length; if (index < line.Length) { if (line[index] == ':') { index += 1; if (index < line.Length && line[index] == ' ') { index += 1; } } else { type = Message.Type.Action; } } } text += index < line.Length ? line.Substring(index) : ""; } var stream = type == Message.Type.Ad ? (ads ?? (ads = File.OpenWrite(Path.Combine(logDir, "Ads")))) : (logs ?? (logs = File.OpenWrite(Path.Combine(logDir, "Logs")))); if (type == Message.Type.Ad) { if (!adsIndexed) { serializer.WriteIndex(adsIndex ?? (adsIndex = File.OpenWrite(Path.Combine(logDir, "Ads.idx"))), file.Date, stream.Position); adsIndexed = true; } } else { if (!logsIndexed) { serializer.WriteIndex(logsIndex ?? (logsIndex = File.OpenWrite(Path.Combine(logDir, "Logs.idx"))), file.Date, stream.Position); logsIndexed = true; } } if (sender.Length > 20) { sender = sender.Substring(0, 20); } serializer.Write(stream, new Message(type, new Character(sender), file.Date.AddMinutes(h * 60 + m), text)); } catch { } } } logs?.Dispose(); ads?.Dispose(); logsIndex?.Dispose(); adsIndex?.Dispose(); } }
public override int OnInviteEvent(InviteEvent e) { tsip_invite_event_type_t type = e.getType(); InviteSession session = e.getSession(); SipMessage message = e.getSipMessage(); switch (type) { case tsip_invite_event_type_t.tsip_i_newcall: SdpMessage sdp = message.getSdpMessage(); if (session != null) { Console.WriteLine("ERRRRRRRRRRRORRRR"); return(0); } else { switch (e.getMediaType()) { case twrap_media_type_t.twrap_media_audio: case twrap_media_type_t.twrap_media_video: case twrap_media_type_t.twrap_media_audiovideo: session = e.takeCallSessionOwnership(); break; case twrap_media_type_t.twrap_media_msrp: if ((session = e.takeMsrpSessionOwnership()) != null) { (session as MsrpSession).setCallback(Program.msrpCallback); } break; } if (session != null) { ActionConfig actionConfig = new ActionConfig(); session.accept(actionConfig); actionConfig.Dispose(); } } /*else if ((session = e.takeSessionOwnership()) != null) * { * SdpMessage sdp = message.getSdpMessage(); * if (sdp != null) * { * String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); * Console.WriteLine("file-selector={0}", fileSelector); * } * * ActionConfig actionConfig = new ActionConfig(); * //actionConfig.setMediaInt(twrap_media_type_t.twrap_media_audiovideo, "bandwidth-level", (int)tmedia_bandwidth_level_t.tmedia_bl_low); * actionConfig.setMediaString(twrap_media_type_t.twrap_media_file, "file-path", "C:\\tmp\\myfile"); * session.accept(actionConfig); * actionConfig.Dispose(); * }*/ break; case tsip_invite_event_type_t.tsip_i_request: break; case tsip_invite_event_type_t.tsip_ao_request: break; case tsip_invite_event_type_t.tsip_o_ect_ok: break; case tsip_invite_event_type_t.tsip_o_ect_nok: break; case tsip_invite_event_type_t.tsip_i_ect: break; case tsip_invite_event_type_t.tsip_m_local_hold_ok: Console.WriteLine("Local Hold OK"); break; case tsip_invite_event_type_t.tsip_m_local_hold_nok: Console.WriteLine("Local Hold NOK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_ok: Console.WriteLine("Local Resume OK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_nok: Console.WriteLine("Local Resume NOK"); break; case tsip_invite_event_type_t.tsip_m_remote_hold: Console.WriteLine("Remote Hold"); break; case tsip_invite_event_type_t.tsip_m_remote_resume: Console.WriteLine("Remote Resume"); break; } return(0); }
/// <summary> /// Call (MSRP, Audio, Video, T.38, ...) events /// </summary> /// <param name="e"></param> /// <returns></returns> public override int OnInviteEvent(InviteEvent e) { tsip_invite_event_type_t type = e.getType(); short code = e.getCode(); String phrase = e.getPhrase(); InviteSession session = e.getSession(); switch (type) { case tsip_invite_event_type_t.tsip_i_newcall: if (session != null) /* As we are not the owner, then the session MUST be null */ { LOG.Error("Invalid incoming session"); session.hangup(); // To avoid another callback event return(-1); } SipMessage message = e.getSipMessage(); if (message == null) { LOG.Error("Invalid message"); return(-1); } twrap_media_type_t sessionType = e.getMediaType(); switch (sessionType) { case twrap_media_type_t.twrap_media_msrp: { if ((session = e.takeMsrpSessionOwnership()) == null) { LOG.Error("Failed to take MSRP session ownership"); return(-1); } MyMsrpSession msrpSession = MyMsrpSession.TakeIncomingSession(this.sipService.SipStack, session as MsrpSession, message); if (msrpSession == null) { LOG.Error("Failed to create new session"); session.hangup(); session.Dispose(); return(0); } msrpSession.State = MyInviteSession.InviteState.INCOMING; InviteEventArgs eargs = new InviteEventArgs(msrpSession.Id, InviteEventTypes.INCOMING, phrase); eargs.AddExtra(InviteEventArgs.EXTRA_SESSION, msrpSession); EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, eargs); break; } case twrap_media_type_t.twrap_media_audio: case twrap_media_type_t.twrap_media_audiovideo: case twrap_media_type_t.twrap_media_video: { if ((session = e.takeCallSessionOwnership()) == null) { LOG.Error("Failed to take audio/video session ownership"); return(-1); } MyAVSession avSession = MyAVSession.TakeIncomingSession(this.sipService.SipStack, session as CallSession, sessionType, message); avSession.State = MyInviteSession.InviteState.INCOMING; InviteEventArgs eargs = new InviteEventArgs(avSession.Id, InviteEventTypes.INCOMING, phrase); eargs.AddExtra(InviteEventArgs.EXTRA_SESSION, avSession); EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, eargs); break; } default: LOG.Error("Invalid media type"); return(0); } break; case tsip_invite_event_type_t.tsip_ao_request: if (code == 180 && session != null) { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.RINGING, phrase)); } break; case tsip_invite_event_type_t.tsip_i_request: case tsip_invite_event_type_t.tsip_o_ect_ok: case tsip_invite_event_type_t.tsip_o_ect_nok: case tsip_invite_event_type_t.tsip_i_ect: { break; } case tsip_invite_event_type_t.tsip_m_early_media: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.EARLY_MEDIA, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_hold_ok: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_HOLD_OK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_hold_nok: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_HOLD_NOK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_resume_ok: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_RESUME_OK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_resume_nok: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_RESUME_NOK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_remote_hold: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.REMOTE_HOLD, phrase)); break; } case tsip_invite_event_type_t.tsip_m_remote_resume: { EventHandlerTrigger.TriggerEvent <InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.REMOTE_RESUME, phrase)); break; } } return(0); }