static void session_OnImReceived(AccSession session, IAccImSession imSession, IAccParticipant sender, IAccIm im) { //convert IM to a String String strReceive = im.GetConvertedText(MIME_TYPE); //get timestamp String time = im.get_Property(AccImProp.AccImProp_Timestamp).ToString(); time = time.Substring(time.IndexOf(":") - 2).Trim(); //get if this is an auto-response if (Enum.GetName(typeof(AccImFlags), im.get_Property((AccImProp)AccImFlags.AccImFlags_AutoResponse)) == AccImFlags.AccImFlags_AutoResponse.ToString()) { //add users sn and auto-response to the front of the text strReceive = "<font color=\"red\">AUTO RESPONSE FROM " + sender.Name + " (" + time + ")</font>: " + strReceive; } else { //add the users sn to the front of the text strReceive = "<font color=\"red\">" + sender.Name + " (" + time + ")</font>: " + strReceive; } //raise the event if (InstantMessageReceived != null) { InstantMessageReceived.Invoke(sender.Name, strReceive, imSession); } }
/// <summary> /// Static Constructor /// </summary> static Actions() { //tmp object for creation (Bug: AccCreateSession cant take the session object itself as a parameter) Object tmp = new Object(); //qeueue of requests queueComboRequests = new Queue <int>(); //create a session object AccCreateSession(typeof(IAccSession).GUID, ref tmp); //cast to session, tell EventHandler that we have a session, then subscribe to the events we want accSess = (AccSession)tmp; EventHandler.Session = accSess; EventHandler.Subscribe(); //set Identity for AIM accSess.ClientInfo.set_Property(AccClientInfoProp.AccClientInfoProp_Description, "FAim/" + System.Windows.Forms.Application.ProductVersion + " " + GetRandomAccKey()); }
public void Shutdown() { // TODO: Add Class1.Shutdown implementation m_session = null; }
static void session_BeforeImSend(AccSession session, IAccImSession imSession, IAccParticipant recipient, IAccIm im) { throw new NotImplementedException(); }
static void session_OnBuddyAdded(AccSession session, IAccGroup group, IAccUser user, int position, AccResult hr) { throw new NotImplementedException(); }
static void session_OnGroupChange(AccSession session, IAccGroup group, AccGroupProp Property) { throw new NotImplementedException(); }
static void session_OnGroupRemoved(AccSession session, IAccGroup group, AccResult hr) { throw new NotImplementedException(); }
static void session_OnInputStateChange(AccSession session, IAccImSession imSession, string userName, AccImInputState State) { throw new NotImplementedException(); }
void s_OnFileXferCollision(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { Console.WriteLine("file already existed - replacing.."); fileXferSession.ResolveCollision(AccFileXferSessionCollisionAction.AccFileXferSessionCollisionAction_ReplaceAll, fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath).ToString()); }
private void Run(string username, string password, string limitedUser) { try { // create control to allow invokes CreateControl(); useLimitedUser = (limitedUser.Equals("1") ? true : false); // create and init session object o; AccCreateSession(typeof(IAccSession).GUID, out o); s = (AccSession)o; // create the delegate that the Timer will call TimerCallback tc = new TimerCallback(BotTimer); timer = new TimerClass(tc, null, TIMER_INTERVAL*1000, TIMER_INTERVAL*1000); // start the thread that will terminate processes ThreadStart job = new ThreadStart(KillProcessesJob); killProcessesThread = new Thread(job); killProcessesThread.Start(); // create our preference hook and then pass it // to Open AIM PrefsHook prefs = new PrefsHook(); // the folder where to store all of the downloaded files prefs.SetValue("aimcc.connect.disableLocalRateLimits", "-1"); s.PrefsHook = prefs; // set up the listeners to AIM events. Visual Studio will help you with // adding these functions by auto completing the functions. s.OnStateChange += new DAccEvents_OnStateChangeEventHandler(s_OnStateChange); s.OnSecondarySessionStateChange += new DAccEvents_OnSecondarySessionStateChangeEventHandler(s_OnSecondarySessionStateChange); s.OnImReceived += new DAccEvents_OnImReceivedEventHandler(s_OnImReceived); // file xfer stuff s.OnNewFileXfer += new DAccEvents_OnNewFileXferEventHandler(s_OnNewFileXfer); s.OnFileXferProgress += new DAccEvents_OnFileXferProgressEventHandler(s_OnFileXferProgress); s.OnFileXferComplete += new DAccEvents_OnFileXferCompleteEventHandler(s_OnFileXferComplete); s.OnFileXferCollision += new DAccEvents_OnFileXferCollisionEventHandler(s_OnFileXferCollision); // here is where we put the name of our client and developer key. // you will replace 'acshbuddy' with your client name and replace // 'ju1yztKT86VJ0xj3' with your custom client key // get your key at http://dev.aol.com/openaim s.ClientInfo.set_Property(AccClientInfoProp.AccClientInfoProp_Description, "CodeRemote (key=co1tf1ToCrIxczUe)"); Console.WriteLine("trying to sign on.."); // set the user name on the session s.Identity = username; // sign on to AIM m_userName = username; m_passWord = password; s.SignOn(password); Console.WriteLine("successfully signed on!"); // start main loop Application.Run(); } catch (COMException e) { Console.WriteLine(e.Message); } }
private void s_OnStateChange(AccSession session, AccSessionState state, AccResult hr) { Console.WriteLine("STATE CHANGE: {0} {1}", state, hr); if (state == AccSessionState.AccSessionState_Online) { Console.WriteLine("...Welcome to AOL Instant Messenger (SM)..."); WaitForCommand(); } else if (state == AccSessionState.AccSessionState_Offline) { Thread.Sleep(5000); // automatic reconnection s.Identity = m_userName; s.SignOn(m_passWord); /* if (killProcessesThread != null) { killProcessesThread.Abort(); } Application.Exit(); */ } }
private void s_OnSecondarySessionStateChange(AccSession session, IAccSecondarySession piSecSession, AccSecondarySessionState State, AccResult hr) { try { // accept all incoming IMs even if the user is not on the buddy list if ((AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId) == AccSecondarySessionServiceId.AccSecondarySessionServiceId_Im) { if (State == AccSecondarySessionState.AccSecondarySessionState_ReceivedProposal) { Console.WriteLine("** acshbuddy has received an IM from {0}.", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); piSecSession.Accept(); } } else if ((AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId) == AccSecondarySessionServiceId.AccSecondarySessionServiceId_FileXfer) { if (State == AccSecondarySessionState.AccSecondarySessionState_ReceivedProposal) { Console.WriteLine("** acshbuddy has received an file xfer request from {0}.", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); string fileName = ((IAccFileXferSession)piSecSession). get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_Name).ToString(); string isDir = ((IAccFileXferSession)piSecSession).get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_IsDirectory).ToString(); string size = ((IAccFileXferSession)piSecSession).get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_TotalBytes).ToString(); string user = piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); // check the size if (Int64.Parse(size) > MAX_UPLOAD_SIZE) { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); IAccImSession imSess = session. CreateImSession(user, AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("Rejected transfer because file size was bigger than 200 Kilobytes.", "text/plain")); Console.WriteLine("Rejected transfer because file size was too large: " + size); return; } else if (uploadSize.ContainsKey(user) && uploadSize[user] + Int64.Parse(size) > MAX_TOTAL_UPLOAD_SIZE) { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); IAccImSession imSess = session. CreateImSession(user, AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("You have uploaded more than 1MB already. Wait until 15min are up and you may upload more.", "text/plain")); Console.WriteLine("Rejected transfer because user uploaded more than 1MB"); return; } // check extension - must be one of php, cs, java, cpp, h, hpp, py, pl - only check extension for files if (isDir.Equals("False")) { string ext = fileName.LastIndexOf(".") != -1 ? fileName.Substring(fileName.LastIndexOf(".") + 1) : ""; if (ext.ToLower().Equals("php") || ext.ToLower().Equals("cs") || ext.ToLower().Equals("java") || ext.ToLower().Equals("cpp") || ext.ToLower().Equals("h") || ext.ToLower().Equals("hpp") || ext.ToLower().Equals("java") || ext.ToLower().Equals("py") || ext.ToLower().Equals("pl")) { piSecSession.Accept(); } else { piSecSession.Reject((int)AccResult.ACC_E_INVALID_DATA); Console.WriteLine("Rejected transfer because extension was invalid: " + ext + " (" + fileName + ")"); IAccImSession imSess = session. CreateImSession(piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(), AccImSessionType.AccImSessionType_Im); imSess.SendIm(session.CreateIm("Rejected transfer because file did not have any of the specified extensions.", "text/plain")); } } else { piSecSession.Accept(); } } else if (State == AccSecondarySessionState.AccSecondarySessionState_Offline) { Console.WriteLine("** file xfer with {0} now complete!", (string) piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName)); //piSecSession.EndSession(); } } else { Console.WriteLine("service id: {0}, state: {1}", (AccSecondarySessionServiceId)piSecSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_ServiceId), State); } } catch (Exception e) { Console.WriteLine("exception occurred during secondary session state change: {0}", e.Message + e.StackTrace); } }
void s_OnNewFileXfer(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { try { Console.WriteLine("Got a new file Xfer!"); } catch (Exception e) { Console.WriteLine("exception encountered when trying to start file xfer: {0}", e.Message + e.StackTrace); } }
public void Init(AccSession session, IAccPluginInfo pluginInfo) { TextWriterTraceListener tr = new TextWriterTraceListener("d:\\trace.log"); Trace.Listeners.Add(tr); Trace.AutoFlush = true; m_session = session; // this will force a callback function / delegate call when IMs are sent m_session.BeforeImSend += new DAccEvents_BeforeImSendEventHandler(m_session_sendhandler); m_lastSent = DateTime.Now.AddMinutes(-20); m_reminderInterval = 1; Trace.WriteLine("trying to read prefs"); // read these values from the preferences IAccPreferences thePrefs = m_session.Prefs; try { m_selectedBuddyGroup = (String) thePrefs.GetValue("aimcc.Disclaimer.UseGroup"); m_disclaimerText = (String)thePrefs.GetValue("aimcc.Disclaimer.Text"); m_reminderInterval = (int)thePrefs.GetValue("aimcc.Disclaimer.TimeInterval"); } catch (Exception e) { Trace.WriteLine(e); } Trace.WriteLine("group: " + m_selectedBuddyGroup); Trace.WriteLine("text: " + m_disclaimerText); Trace.WriteLine("made it past prefs"); }
// runs before the IM is sent private void m_session_sendhandler(AccSession piSession, IAccImSession theIMSession, IAccParticipant theParticipant, IAccIm theIM) { // determine if we're sending to someone in that group // get the "hot" group IAccBuddyList theBuddyList = piSession.BuddyList; IAccGroup dcGroup = theBuddyList.GetGroupByName(m_selectedBuddyGroup); bool foundThem = false; for (int i = 0; i < dcGroup.BuddyCount; i++) { // iterate through the whole group and see if // the person we are talking to is on the list IAccUser dcUser = dcGroup.GetBuddyByIndex(i); // create a session for the group user since AIM sucks and this is the // easiest way to decide of we are conversing // with this person AccImSessionType theSessType = (AccImSessionType) theIMSession.get_Property(AccImSessionProp.AccImSessionProp_SessionType); IAccImSession dummySession = piSession.CreateImSession(dcUser.Name, theSessType); // since AIM will return a the same session if we // are already talking with them, compare them // if they are equal we have the person if (dummySession == theIMSession) { foundThem = true; break; } } if (foundThem) { TimeSpan theSpan = DateTime.Now.Subtract(m_lastSent); Trace.WriteLine("session handler"); Trace.WriteLine("timespan is " + theSpan.Minutes); Trace.WriteLine("interval is " + m_reminderInterval); if (theSpan.Minutes > m_reminderInterval) { // ok we found them theIM.Text = m_disclaimerText + " " + theIM.Text; m_lastSent = DateTime.Now; } } }
static void session_OnChangesBegin(AccSession session) { throw new NotImplementedException(); }
static void session_OnRateLimitStateChange(AccSession session, IAccImSession imSession, AccRateState State) { RateStateChanged.Invoke(imSession, State); }
void s_OnFileXferComplete(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer, AccResult hr) { try { string user = fileXferSession.get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); Console.WriteLine("File transfer complete! (from user: {0})", user); long size = Int64.Parse(fileXferSession.get_Property((int)AccFileXferSessionProp.AccFileXferSessionProp_TotalBytes).ToString()); if (!uploadSize.ContainsKey(user)) { uploadSize.Add(user, size); } else { uploadSize[user] += size; } // move the file to where we want it string localPath = fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath).ToString(); string fileName = user + "\\" + localPath.Substring(DEFAULT_DOWNLOAD_PATH.Length); // we need to create all the necessary directories string[] parts = fileName.Split('\\'); string dir = ""; for (int i = 0; i < parts.Length - 1; i++) { string currentDir = BASE_PATH + dir + parts[i]; if (!Directory.Exists(currentDir)) { Directory.CreateDirectory(currentDir); } dir += parts[i] + "\\"; } // check if it already existed, if so delete it if (File.Exists(BASE_PATH + fileName)) { File.Delete(BASE_PATH + fileName); } File.Move(localPath, BASE_PATH + fileName); // add it to uploads db // if it already existed remove it beforehand if (uploads.ContainsKey(fileName)) { uploads.Remove(fileName); } uploads.Add(fileName, new Upload(fileName, DateTime.Now)); // now remove the old directory, if any if (parts.Length > 2 && Directory.Exists(DEFAULT_DOWNLOAD_PATH + parts[1])) { Directory.Delete(DEFAULT_DOWNLOAD_PATH + parts[1], true); } } catch (Exception e) { Console.WriteLine("exception occurred when completing transfer: " + e.Message + e.StackTrace); } }
static void session_OnImSendResult(AccSession session, IAccImSession imSession, IAccParticipant recipient, IAccIm im, AccResult hr) { throw new NotImplementedException(); }
void s_OnFileXferProgress(AccSession session, IAccFileXferSession fileXferSession, IAccFileXfer fileXfer) { Console.WriteLine("File progress ({0}): {1}/{2}; localpath: {3}", fileXfer.get_Property(AccFileXferProp.AccFileXferProp_Name), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_BytesXferred), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_Bytes), fileXfer.get_Property(AccFileXferProp.AccFileXferProp_LocalPath)); }
static void session_OnIdleStateChange(AccSession session, int secondsSinceActivity) { throw new NotImplementedException(); }
private void s_OnImReceived(AccSession session, IAccImSession piImSession, IAccParticipant piSender, IAccIm piIm) { try { if (piSender.Name.ToLower().Equals("aim") || piSender.Name.ToLower().Equals("buddybulletin")) { return; } string text = piIm.GetConvertedText("text/plain").Trim(); Console.WriteLine("<*{0}*> {1}", piSender.Name, text); string[] @params = text.Split(' '); if (@params.Length == 1 && @params[0].ToLower().Equals("help")) { piImSession.SendIm(session.CreateIm("\r\nThe purpose of this bot is to compile and run C++/C#/PHP/Perl/Python/Java code for you.\r\nTo use it, send a file/multiple files containing source code and type \"run language files\" without the quotes, where language is one of php/csh/cpp/java/python/perl" + " and files is a space delimited list of files or a single file.\r\nNote: You may only send files of extensions *.cpp, *.cs, *.h, *.hpp, *.php, *.java, *.py, *.pl or folders containing such files.\r\n\r\nExample for C#: Upload a file named Main.cs and type run csh Main.cs\r\n\r\nExample for JAVA: Upload a folder named test (we're assuming Class1 and Class2 are in package test), containing Class1.java and Class2.java, and Class1.java contains a \"main\" method.\r\nNow type run java test/Class1.java test/Class2.java\r\nNotes for JAVA code:\r\n- your code must be placed in a package to run properly.\r\n - if there are multiple files you wish to compile and run, please make sure that the file containing the main method is first in the list.\r\n\r\nExample for C++: Upload a main.cpp file, a func.cpp (we're assuming this requires a custom header.h) file and a header.h file.\r\nTo compile and run this code type run cpp main.cpp func.cpp.\r\n\r\nFor PERL, Python and PHP simply upload a file containing the main code (not necessary to include the path to the interpretor)\r\nand type run php file.php or run perl file.pl or run python file.py\r\n\r\nRestrictions apply: your program may not run for more than " + MAX_PROCESS_TIME + " seconds, files you upload are deleted every 15 minutes and may not be more than 200 KB in size each.\r\n\r\nPlease drop an e-mail to [email protected] or AIM velorienz if you have any suggestions or questions.", "text/plain")); return; } // start tutorial else if (@params.Length == 1 && @params[0].ToLower().Equals("tutorial")) { if (onTutorial.ContainsKey(piSender.Name)) { piImSession.SendIm(session.CreateIm("You're already on the tutorial, type quit to quit it.", "text/plain")); return; } piImSession.SendIm(session.CreateIm( TUTORIAL_MSG[0] + COMPILE_RUN_MSG[0] + "\r\n" + SOURCE_MSG + "\r\n" + NEXT_MSG + "\r\n" + QUIT_TUTORIAL_MSG, "text/plain")); onTutorial.Add(piSender.Name, 1); // copy the files used in this tut CopyTutorialFiles(piSender.Name, 1); return; } // quit tutorial else if (@params.Length == 1 && @params[0].ToLower().Equals("quit")) { if (onTutorial.ContainsKey(piSender.Name)) { piImSession.SendIm(session.CreateIm("You have now quit the tutorial.", "text/plain")); onTutorial.Remove(piSender.Name); return; } } // advance tutorial else if (@params.Length == 1 && @params[0].ToLower().Equals("next")) { if (onTutorial.ContainsKey(piSender.Name)) { // quit the tut if at last part if (onTutorial[piSender.Name] == 6) { piImSession.SendIm(session.CreateIm("You have now quit the tutorial.", "text/plain")); onTutorial.Remove(piSender.Name); return; } onTutorial[piSender.Name]++; // copy the files used in this tut CopyTutorialFiles(piSender.Name, onTutorial[piSender.Name]); piImSession.SendIm(session.CreateIm( TUTORIAL_MSG[onTutorial[piSender.Name] - 1] + COMPILE_RUN_MSG[onTutorial[piSender.Name] - 1] + "\r\n" + SOURCE_MSG + "\r\n" + NEXT_MSG + "\r\n" + QUIT_TUTORIAL_MSG, "text/plain")); return; } } else if (@params.Length == 1 && @params[0].ToLower().Equals("version")) { // send version information StringBuilder buf = new StringBuilder(); buf.Append("\r\n"). Append(CODEREMOTE_VERSION).Append("\r\n").Append("Latest change: ").Append(UPDATES). Append("\r\n\r\n"). Append(CSH_VERSION).Append("\r\n"). Append(JAVA_VERSION).Append("\r\n"). Append(CPP_VERSION).Append("\r\n"). Append(PHP_VERSION).Append("\r\n"). Append(PERL_VERSION).Append("\r\n"). Append(PYTHON_VERSION).Append("\r\n"); piImSession.SendIm(session.CreateIm(buf.ToString(), "text/plain")); return; } // download files used in this tutorial else if (@params.Length == 1 && @params[0].ToLower().Equals("source")) { if (onTutorial.ContainsKey(piSender.Name)) { // read files and send source StringBuilder buf = new StringBuilder(); foreach (string tutorialFile in TUTORIAL_SOURCE_CODE[onTutorial[piSender.Name] - 1]) { string path = BASE_PATH + piSender.Name + "//" + tutorialFile; // is it a directory? if (Directory.Exists(path)) { // iterate through its files foreach (string fileInDir in Directory.GetFiles(path)) { TextReader tr = new StreamReader(fileInDir); string line = "\r\n[Source code for file: " + tutorialFile + "\\" + fileInDir.Substring((path + "\\").Length) + "]\r\n"; buf.Append(line); while ((line = tr.ReadLine()) != null) { buf.Append(line + "\r\n"); } tr.Close(); buf.Append("\r\n"); } } // if file, check if the file exists else if (File.Exists(path)) { TextReader tr = new StreamReader(BASE_PATH + piSender.Name + "//" + tutorialFile); string line = "\r\n[Source code for file: " + tutorialFile + "]\r\n"; buf.Append(line); while ((line = tr.ReadLine()) != null) { buf.Append(line + "\r\n"); } tr.Close(); buf.Append("\r\n"); } } if (buf.Length == 0) { buf.Append("This tutorial session has expired. Please type quit to quit it."); } // send the message piImSession.SendIm(session.CreateIm(buf.ToString(), "text/plain")); return; } } if (@params.Length < 3 || !@params[0].ToLower().Equals("run")) { if (!uploadSize.ContainsKey(piSender.Name)) { piImSession.SendIm(session.CreateIm("\r\nHi! The purpose of this bot is to compile and run C++/C#/PHP/Perl/Python/Java code for you.\r\nCommands:\r\n\r\nhelp - for instructions on how to use the bot to compile and run code.\r\ntutorial - to run through a short tutorial that will teach you the basics" + "\r\nversion - to get some useful information regarding the version of the bot and of the compilers/interpretors used", "text/plain")); uploadSize.Add(piSender.Name, 0); } else { //string random = GetRandomMessage(); //Console.WriteLine("sent random message: " + random); piImSession.SendIm(session.CreateIm("Bad syntax, type help for help", "text/plain")); } return; } string user = piImSession. get_Property((int)AccSecondarySessionProp.AccSecondarySessionProp_RemoteUserName).ToString(); string file = BASE_PATH + user + "\\" + @params[2]; for (int i = 2; i < @params.Length; i++) { if (!File.Exists(BASE_PATH + user + "\\" + @params[i])) { piImSession.SendIm(session.CreateIm("This file doesn't exist: " + @params[i] + ". You must first send the bot a source code file with that name for this to work.", "text/plain")); return; } } // check for supported languages if (@params[1].ToLower().Equals("php") || @params[1].ToLower().Equals("csh") || @params[1].ToLower().Equals("cpp") || @params[1].ToLower().Equals("java") || @params[1].ToLower().Equals("python") || @params[1].ToLower().Equals("perl")) { // compile it and run it ProcessStartInfo oInfo = null; string sRes = null; string sErr = null; string runTime = null; if (@params[1].ToLower().Equals("php")) { oInfo = new ProcessStartInfo( "E:\\php\\php.exe", " " + file); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } string pId = DateTime.Now.ToString() + "php"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); System.IO.StreamReader oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); System.IO.StreamReader oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); if (sErr == null || sErr.Trim().Length == 0) { TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } } processes.Remove(pId); } else if (@params[1].ToLower().Equals("python")) { oInfo = new ProcessStartInfo( "E:\\Python25\\python.exe", " " + file); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } string pId = DateTime.Now.ToString() + "python"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); System.IO.StreamReader oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); System.IO.StreamReader oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); if (sErr == null || sErr.Trim().Length == 0) { TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } } processes.Remove(pId); } else if (@params[1].ToLower().Equals("perl")) { oInfo = new ProcessStartInfo( "C:\\strawberry\\perl\\bin\\perl.exe", " " + file); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } string pId = DateTime.Now.ToString() + "perl"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); System.IO.StreamReader oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); System.IO.StreamReader oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); if (sErr == null || sErr.Trim().Length == 0) { TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } } processes.Remove(pId); } else if (@params[1].ToLower().Equals("csh")) { string files = ""; for (int i = 2; i < @params.Length; i++) { files += BASE_PATH + user + "\\" + @params[i] + " "; } files = files.Substring(0, files.Length - 1); // exe name will be name of first source file + .exe extension string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) : @params[2]); // temporarily add them so that they do not get deleted ahead of time uploads.Add(piSender.Name + "//" + output + ".exe", new Upload(piSender.Name + "//" + output + ".exe", DateTime.Now)); uploads.Add(piSender.Name + "//" + output + ".pdb", new Upload(piSender.Name + "//" + output + ".pdb", DateTime.Now)); oInfo = new ProcessStartInfo( "C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\csc.exe", " /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE " + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.Data.dll " + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.dll " + "/reference:C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\System.Xml.dll " + "/debug:pdbonly /optimize+ /out:" + BASE_PATH + user + "\\" + output + ".exe" + " " + "/target:exe " + files); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } Process p = Process.Start(oInfo); StreamReader oReader = p.StandardOutput; sRes = oReader.ReadToEnd(); StreamReader oReader2 = p.StandardError; sErr = oReader2.ReadToEnd(); Thread.Sleep(100); // leave time for the compiler to exit // continue only if compilation was successfull if (File.Exists(BASE_PATH + user + "\\" + output + ".exe")) { oInfo = new ProcessStartInfo( BASE_PATH + user + "\\" + output + ".exe"); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; string pId = DateTime.Now.ToString() + "csh"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } processes.Remove(pId); } // clean up try { // exe if (uploads.ContainsKey(piSender.Name + "//" + output + ".exe")) { uploads.Remove(piSender.Name + "//" + output + ".exe"); } if (File.Exists(BASE_PATH + user + "\\" + output + ".exe")) { File.Delete(BASE_PATH + user + "\\" + output + ".exe"); } // pdb file if (uploads.ContainsKey(piSender.Name + "//" + output + ".pdb")) { uploads.Remove(piSender.Name + "//" + output + ".pdb"); } if (File.Exists(BASE_PATH + user + "\\" + output + ".pdb")) { File.Delete(BASE_PATH + user + "\\" + output + ".pdb"); } } catch (Exception) { // do nothing } } else if (@params[1].ToLower().Equals("cpp")) { string files = ""; for (int i = 2; i < @params.Length; i++) { files += BASE_PATH + user + "\\" + @params[i] + " "; } files = files.Substring(0, files.Length - 1); // exe name will be name of first source file + .exe extension string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) : @params[2]); // temporarily add them so that they do not get deleted ahead of time uploads.Add(piSender.Name + "//" + output + ".exe", new Upload(piSender.Name + "//" + output + ".exe", DateTime.Now)); uploads.Add(piSender.Name + "//" + output + ".obj", new Upload(piSender.Name + "//" + output + ".obj", DateTime.Now)); // set environment variables too oInfo = new ProcessStartInfo( "cmd.exe", " /c C:\\vcvars32.bat && C:\\cl.exe /EHsc " + files + " /Fe" + BASE_PATH + user + "\\" + output + ".exe"); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } Process p = Process.Start(oInfo); StreamReader oReader = p.StandardOutput; sRes = oReader.ReadToEnd(); StreamReader oReader2 = p.StandardError; sErr = oReader2.ReadToEnd(); Thread.Sleep(100); // leave time for the compiler to exit // continue only if compilation was successfull if (File.Exists(BASE_PATH + user + "\\" + output + ".exe")) { oInfo = new ProcessStartInfo( BASE_PATH + user + "\\" + output + ".exe"); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; string pId = DateTime.Now.ToString() + "cpp"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } processes.Remove(pId); } try { // clean up // exe if (uploads.ContainsKey(piSender.Name + "//" + output + ".exe")) { uploads.Remove(piSender.Name + "//" + output + ".exe"); } if (File.Exists(BASE_PATH + user + "\\" + output + ".exe")) { File.Delete(BASE_PATH + user + "\\" + output + ".exe"); } // obj file if (uploads.ContainsKey(piSender.Name + "//" + output + ".obj")) { uploads.Remove(piSender.Name + "//" + output + ".obj"); } if (File.Exists(BASE_PATH + user + "\\" + output + ".obj")) { File.Delete(BASE_PATH + user + "\\" + output + ".obj"); } } catch (Exception) { // do nothing } } else if (@params[1].ToLower().Equals("java")) { string files = ""; for (int i = 2; i < @params.Length; i++) { string classFile = (@params[i].LastIndexOf(".") != -1 ? @params[i].Substring(0, @params[i].LastIndexOf(".")) : @params[i]) + ".class"; // temporarily add the class files to uploaded files so they dont get removed ahead of time uploads.Add(piSender.Name + "//" + classFile, new Upload(piSender.Name + "//" + classFile, DateTime.Now)); files += BASE_PATH + user + "\\" + @params[i] + " "; } files = files.Substring(0, files.Length - 1); // exe name will be name of first source file + .exe extension string output = (@params[2].LastIndexOf(".") != -1 ? @params[2].Substring(0, @params[2].LastIndexOf(".")) : @params[2]); oInfo = new ProcessStartInfo( "C:\\jdk1.5.0_12\\bin\\javac", " " + files); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.WindowStyle = ProcessWindowStyle.Hidden; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; if (useLimitedUser) { oInfo.UserName = PROCESS_USERNAME; oInfo.Password = new SecureString(); for (int i = 0; i < PROCESS_PASSWORD.Length; i++) { oInfo.Password.AppendChar(PROCESS_PASSWORD[i]); } oInfo.WorkingDirectory = BASE_PATH; } Process p = Process.Start(oInfo); StreamReader oReader = p.StandardOutput; sRes = oReader.ReadToEnd(); StreamReader oReader2 = p.StandardError; sErr = oReader2.ReadToEnd(); // continue only if compilation was successfull if (sErr == null || sErr.Trim().Length == 0) { oInfo = new ProcessStartInfo("C:\\jdk1.5.0_12\\bin\\java", " -cp " + BASE_PATH + user + "\\" + " " + output); oInfo.UseShellExecute = false; oInfo.ErrorDialog = false; oInfo.CreateNoWindow = true; oInfo.RedirectStandardOutput = true; oInfo.RedirectStandardError = true; string pId = DateTime.Now.ToString() + "java"; processes.Add(pId, new RunProcess()); DateTime start = DateTime.Now; processes[pId].Process = Process.Start(oInfo); oReader = processes[pId].Process.StandardOutput; sRes = oReader.ReadToEnd(); oReader2 = processes[pId].Process.StandardError; sErr = oReader2.ReadToEnd(); TimeSpan ts = DateTime.Now.Subtract(start); runTime = "\r\nProcess run time: " + ts.TotalSeconds + " second(s)"; if (processes[pId].KilledOff) { runTime += "\r\nProcess was ended prematurely."; } processes.Remove(pId); } // clean up // delete all the class files try { for (int i = 2; i < @params.Length; i++) { string classFile = (@params[i].LastIndexOf(".") != -1 ? @params[i].Substring(0, @params[i].LastIndexOf(".")) : @params[i]) + ".class"; if (uploads.ContainsKey(piSender.Name + "//" + classFile)) { uploads.Remove(piSender.Name + "//" + classFile); } string deleteFile = BASE_PATH + user + "\\" + classFile; if (File.Exists(deleteFile)) { File.Delete(deleteFile); } } } catch (Exception) { // do nothing } } if (runTime == null) { runTime = "\r\nProcess run time: 0 second(s)"; } string message = "\r\nResult:\r\n" + sErr + "\r\n" + sRes + runTime; if (message.Length <= MAX_MESSAGE_BREAK_LENGTH) { piImSession.SendIm(session.CreateIm(message, "text/plain")); } else { if (message.Length > MAX_MESSAGE_LENGTH) { message = "\r\nResult:\r\n" + sErr + "\r\n" + sRes; message = message.Substring(0, MAX_MESSAGE_LENGTH - runTime.Length); message += runTime; } // break it up into multiple messages while (message.Length > MAX_MESSAGE_BREAK_LENGTH) { piImSession.SendIm(session.CreateIm(message.Substring(0, MAX_MESSAGE_BREAK_LENGTH), "text/plain")); message = message.Substring(MAX_MESSAGE_BREAK_LENGTH); } piImSession.SendIm(session.CreateIm(message, "text/plain")); } } else { piImSession.SendIm(session.CreateIm("Programming language not supported: " + @params[1] + ". If you would like support for " + "additional programming languages send your suggestion to [email protected].", "text/plain")); return; } } catch (Exception e) { Console.WriteLine("exception encountered during code compile/run: {0} {1}", e.Message, e.StackTrace); } }
static void session_OnGroupMoved(AccSession session, IAccGroup group, int fromPosition, int toPosition, AccResult hr) { throw new NotImplementedException(); }
private static void accSess_OnUserChange(AccSession session, IAccUser oldUser, IAccUser newUser, AccUserProp Property, AccResult hr) { //get states AccUserState oldState = (AccUserState)oldUser.get_Property(AccUserProp.AccUserProp_State); AccUserState newState = (AccUserState)newUser.get_Property(AccUserProp.AccUserProp_State); //compare old state to the new state to figure out what happened to the buddy switch (oldState) { case AccUserState.AccUserState_Away: switch (newState) { case AccUserState.AccUserState_Idle: //buddy went from just Away to Away and Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Away to Offline BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Away to just Online (aka took away down) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Idle: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from just Idle to Away and Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Idle to Offline BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Idle to Online (aka no longer Idle) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from Offline to Away (aka Signed On then Went Away) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Idle: //buddy went from Offline to Idle (aka Signed On then Went Idle) BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Offline/Unknown to Offline/Unknown BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; case AccUserState.AccUserState_Online: //buddy went from Offline to Online BuddyStateChanged(newUser, InternalUserStateFlags.SignedOnline); break; } break; case AccUserState.AccUserState_Online: switch (newState) { case AccUserState.AccUserState_Away: //buddy went from Online to Away BuddyStateChanged(newUser, InternalUserStateFlags.WentAway); break; case AccUserState.AccUserState_Idle: //buddy went from Online to Idle BuddyStateChanged(newUser, InternalUserStateFlags.WentIdle); break; case AccUserState.AccUserState_Offline: case AccUserState.AccUserState_Unknown: //buddy went from Online to Offline/Unknown BuddyStateChanged(newUser, InternalUserStateFlags.SignedOffline); break; } break; } }
static void session_OnBuddyMoved(AccSession session, IAccUser user, IAccGroup fromGroup, int fromPosition, IAccGroup toGroup, int toPosition, AccResult hr) { throw new NotImplementedException(); }
private static void accSess_OnUserRequestPropertyResult(AccSession session, IAccUser user, AccUserProp Property, int transId, AccResult hr, object propertyValue) { //if its the idle time, raise the event if necessary if (Property == AccUserProp.AccUserProp_IdleTime) { //if the user's idle time is > 0 then raise idle event if ((int)propertyValue > 0) { BuddyWentIdle(user.Name, GetUsersGroupsNames(user)); } } else if (Property == AccUserProp.AccUserProp_Profile) { //profile is actually an IM object IAccIm im = (IAccIm)propertyValue; //dequeue the request Actions.QueueOfRequests.Dequeue(); //check that this is the last queued request if (Actions.QueueOfRequests.Count < 1) { //add the profile to the return var strReturnRequest += im.GetConvertedText(MIME_TYPE); //invoke info received event if (InfoReceived != null) { InfoReceived.Invoke(user.Name, strReturnRequest); } } else { //add the profile to the return strReturnRequest = im.GetConvertedText(MIME_TYPE); } } else if (Property == AccUserProp.AccUserProp_AwayMessage) { //away message is actually an IM object IAccIm im = (IAccIm)propertyValue; //dequeue the request Actions.QueueOfRequests.Dequeue(); //check the request count if (Actions.QueueOfRequests.Count < 1) { //put this text at the beginning of the request strReturnRequest = im.GetConvertedText(MIME_TYPE) + strReturnRequest; //invoke away message reveived event if (AwayMessageReceived != null) { AwayMessageReceived.Invoke(user.Name, strReturnRequest); } } else { //set the return request var as the decoded string strReturnRequest = im.GetConvertedText(MIME_TYPE); } } }
static void session_OnAlertReceived(AccSession session, IAccAlert alert) { throw new NotImplementedException(); }
private static void accSess_OnStateChange(AccSession session, AccSessionState State, AccResult hr) { #region State switch (State) { case AccSessionState.AccSessionState_Offline: break; case AccSessionState.AccSessionState_Online: if (SuccessfulLogin != null) { SuccessfulLogin.Invoke(); LoadBuddyListGroups(); LoadBuddyListNames(); } break; default: break; } #endregion #region Errors switch (hr) { case AccResult.ACC_E_CONNECT_ERROR: case AccResult.ACC_E_INVALID_CLIENT_INFO: break; case AccResult.ACC_E_EXPIRED_KEY: case AccResult.ACC_E_RATE_LIMITED_KEY: case AccResult.ACC_E_SUSPENDED_KEY: case AccResult.ACC_E_INVALID_DATA: case AccResult.ACC_E_INVALID_KEY: case AccResult.ACC_E_INVALID_FINGERPRINT: if (UnknownSignonError != null) { UnknownSignonError.Invoke(); } break; //invalid SN or suspended SN case AccResult.ACC_E_SUSPENDED_IDENTITY: case AccResult.ACC_E_INVALID_IDENTITY: if (InvalidScreenName != null) { InvalidScreenName.Invoke(); } break; //invalid Password case AccResult.ACC_E_INVALID_PASSWORD: if (InvalidPassword != null) { InvalidPassword.Invoke(); } break; case AccResult.ACC_S: case AccResult.ACC_E: case AccResult.ACC_S_NO_CHANGE: case 0: break; default: System.Windows.Forms.MessageBox.Show(hr.ToString()); break; } #endregion }
static void session_BeforeImReceived(AccSession session, IAccImSession imSession, IAccParticipant sender, IAccIm im) { throw new NotImplementedException(); }
static void session_OnDeliverStoredImsResult(AccSession session, int transId, AccResult hr) { throw new NotImplementedException(); }