public void Update() { Callback callback; SteamCallHandle steamCall; if (Steamworks.Steam_BGetCallback(pipe, out callback, out steamCall)) { if (callback.CallbackNum == FriendChatMsg.Callback) { FriendChatMsg chatMsg = null; try { chatMsg = ( FriendChatMsg )callback.CallbackObject; } catch { Steamworks.Steam_FreeLastCallback(pipe); OnLogFailure(new LogFailureEventArgs("Recieved callback was not in the correct format, call a programmer!")); return; } string message = string.Empty; FriendMsgType type; SteamID reciever = new SteamID(chatMsg.Reciever); steamFriends.GetChatMessage(reciever, ( int )chatMsg.ChatID, out message, 1024 * 4, out type); LogMessage log = new LogMessage(); log.Sender = new SteamID(chatMsg.Sender); log.SenderName = steamFriends.GetFriendPersonaName(log.Sender); log.Reciever = reciever; log.RecieverName = steamFriends.GetFriendPersonaName(log.Reciever); log.Message = message; log.MessageTime = DateTime.Now; log.MessageType = type; AddLog(log); } Steamworks.Steam_FreeLastCallback(pipe); } }
static void Main(string[] args) { int error; steamClient = (SteamClient008)Steamworks.CreateInterface(SteamClient008.InterfaceVersion, out error); if (steamClient == null) { Console.WriteLine("Unable to get SteamClient."); return; } pipe = steamClient.CreateSteamPipe(); user = steamClient.ConnectToGlobalUser(pipe); _handler += new EventHandler(ConsoleEvent); SetConsoleCtrlHandler(_handler, true); steamFriends = ( SteamFriends001 )steamClient.GetISteamFriends(user, pipe, SteamFriends001.InterfaceVersion); steamUser = (SteamUser012)steamClient.GetISteamUser(user, pipe, SteamUser012.InterfaceVersion); FriendsName = steamFriends.GetPersonaName(); RelayTargets = new List <RelayUser>(); ircClient = new IrcClient(RelayNick); ircClient.AlternateNickname = RelayNick + "`"; ircClient.Debugger.Debugging = DebugMode.All; ConnectionParser connection = ircClient.ConnectionParser; MessageParser message = ircClient.MessageParser; connection.Connected += new EventHandler <InfoEventArgs>(connection_Connected); message.ChannelMessage += new EventHandler <MessageEventArgs>(message_ChannelMessage); running = ircClient.Connect(RelayNetwork); DateTime lastUpdate = DateTime.Now; while (running) { ircClient.UpdateIn(); if ((DateTime.Now - lastUpdate) >= RelayDelay && connected) { ircClient.UpdateOut(); lastUpdate = DateTime.Now; } else { ircClient.UpdateOut(); } if (!connected) { continue; } Callback callback; SteamCallHandle steamCall; if (Steamworks.Steam_BGetCallback(pipe, out callback, out steamCall)) { Console.WriteLine("Callback: " + callback.CallbackNum); if (callback.CallbackNum == FriendChatMsg.Callback) { FriendChatMsg chatMsg = ( FriendChatMsg )callback.CallbackObject; SteamID sender = new SteamID(chatMsg.Sender); SteamID reciever = new SteamID(chatMsg.Reciever); if (sender.Equals(steamUser.GetSteamID())) { Steamworks.Steam_FreeLastCallback(pipe); continue; } string msg; FriendMsgType msgType; steamFriends.GetChatMessage(reciever, ( int )chatMsg.ChatID, out msg, 400, out msgType); if (msgType != FriendMsgType.Chat) { Steamworks.Steam_FreeLastCallback(pipe); continue; } string senderStr = steamFriends.GetFriendPersonaName(sender); msg = msg.Replace("\n", " ").Replace("\r", " ").Replace("DCC", ""); RelayUser ru = new RelayUser() { SteamID = sender, LastMessage = DateTime.Now.Subtract(TimeSpan.FromSeconds(1)), }; if (!RelayTargets.Contains(ru)) { RelayTargets.Add(ru); } RelayUser realUser = RelayTargets.Find(new Predicate <RelayUser>((ruser) => { return(ruser.SteamID.Equals(sender)); })); if (msg.StartsWith("!relayon")) { realUser.RelayingIRC = true; steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You are now added to the relay list."); } else if (msg.StartsWith("!relayoff")) { realUser.RelayingIRC = false; steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You have been removed from the relay list."); } else { if (!realUser.RelayingIRC) { Steamworks.Steam_FreeLastCallback(pipe); continue; } if ((DateTime.Now - realUser.LastMessage) >= TimeSpan.FromSeconds(1)) { realUser.LastMessage = DateTime.Now; ircClient.SendMessage(RelayChannel, senderStr + ": " + msg); } else { steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You are sending messages too fast."); } } } Steamworks.Steam_FreeLastCallback(pipe); } } }