Example #1
0
 private List<ChatLog> CreateDeepListCopy(List<ChatLog> list)
 {
     if (list == null) return new List<ChatLog>();
     else
     {
         List<ChatLog> deepCpy = new List<ChatLog>();
         foreach (ChatLog aLog in list)
         {
             ChatLog newLog = new ChatLog();
             newLog.message = aLog.message;
             newLog.time = aLog.time;
             newLog.playerName = aLog.playerName;
             deepCpy.Add(newLog);
         }
         return deepCpy;
     }
 }
Example #2
0
        public void UpdateLocalLogList()
        {
            if (busyUpdating == true) return;

            try
            {
                busyUpdating = true;
                Console.WriteLine("attempting globalchat http req");
                WebRequest req = WebRequest.Create(this.httpSource + "/G");

                WebResponse resp = req.GetResponse();
                Console.WriteLine("requestReceived[]");

                Stream resStream = resp.GetResponseStream();

                //used on each read operation
                byte[] buf = new byte[10000];

                // to build entire output
                StringBuilder sb = new StringBuilder();

                string tempString = null;
                int count = 0;

                do
                {
                    // fill the buffer with data
                    count = resStream.Read(buf, 0, buf.Length);

                    // make sure we read some data
                    if (count != 0)
                    {
                        // translate from bytes to ASCII text
                        tempString = Encoding.ASCII.GetString(buf, 0, count);

                        // continue building the string
                        sb.Append(tempString);
                    }
                }
                while (count > 0); // any more data to read?

                //Console.WriteLine(sb.ToString());

                //empty logs and get fresh batch
                //chatLogs.Clear();
                //unsafe for multithreading

                updateList = new List<ChatLog>();

                //Parse the stringBuffer into lists
                count = 0;
                StringBuilder sb2 = new StringBuilder();
                for (int i = 0; i < sb.Length; i++)
                {
                    if (sb[i] == '\n')
                    {
                        //log should be greater than 3 characters in length
                        if (sb2.ToString().Length > 11)
                        {
                            string parsed_log = sb2.ToString();
                            ChatLog log = new ChatLog();
                            int msgStart = sb2.ToString().IndexOf(':');
                            log.message = sb2.ToString().Substring(msgStart);
                            log.playerName = sb2.ToString().Substring(0, msgStart);

                            updateList.Add(log);

                        }

                        sb2.Clear();
                    }
                    else
                    {
                        sb2.Append(sb[i]);
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("Could not update global chat, is the game connected to internet?");

            }
            finally
            {

                busyUpdating = false;
                LogsUpdated = true;
            }

            return;
        }