Beispiel #1
0
        /// <summary>
        /// Method used to extract the world size and playerID from the server
        /// </summary>
        /// <param name="ss"></param>
        private void ExtractFirstData(SocketState ss)
        {
            string message;

            lock (ss.sb)
            {
                message = (ss.sb.ToString());

                // Clear the string builder in the socket state
                ss.sb.Remove(0, ss.sb.Length);
            }

            ReceivedMessage l = JsonConvert.DeserializeObject <ReceivedMessage>(message);


            SendSetupToView(l.spreadsheets);
        }
Beispiel #2
0
        /// <summary>
        /// Method that extracts data from the messagebuffer in the socket state
        /// </summary>
        /// <param name="ss">Socket state whose message buffer data is extracted from</param>
        public void ReceiveWorld(SocketState ss)
        {
            string message;

            lock (ss.sb)
            {
                message = (ss.sb.ToString());

                // Clear the string builder in the socket state
                ss.sb.Remove(0, ss.sb.Length);
            }
            string[] parts = message.Split(new [] { "\n\n" }, StringSplitOptions.None);

            foreach (string p in parts)
            {
                ReceivedMessage m = JsonConvert.DeserializeObject <ReceivedMessage>(p);
                if (m != null)
                {
                    if (m.type == "error")
                    {
                        if (m.code == 1)
                        {
                            ErrorCodeOne();
                        }
                        if (m.code == 2)
                        {
                            ErrorCodeTwo(m.source);
                        }
                    }
                    else
                    {
                        UpdateSpreadsheet(m.spreadsheet);
                    }
                }
            }

            try
            {
                Networking.GetData(ss);
            }
            catch (Exception)
            {
                ResetConnection();
            }
        }