/// <summary>
            /// Low level byte array data send ( without any checks or sth )
            /// </summary>
            /// <param name="data">Byte array of data</param>
            /// <returns></returns>
            protected bool Send_LowLevel(byte[] data)
            {
                if (!active || disposed)
                {
                    return(false);
                }

                try
                {
                    //byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes(data);
                    //Encoding.
                    try
                    {
                        stream.Write(data, 0, data.Length);
                    }
                    catch (System.IO.IOException e)
                    {
                        NetworkEngine.WriteError(e.Message);
                        socket.Close();
                        active = false;
                        return(false);
                    }
                }
                catch (InvalidOperationException e)
                {
                    Debug.LogError(e.Message + " at " + e.Source + " in Send_LowLevel()");
                    socket.Close();
                    active = false;
                    return(false);
                }
                return(true);
            }
示例#2
0
        private static bool FileParseExample(string configFilePath)
        {
            //games = new List<Game>();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Init");

            if (!File.Exists(configFilePath))
            {
                NetworkEngine.WriteError("Games config file on path \"" + configFilePath + "\" doesn't exist");
                return(false);
            }

            string[] lines = File.ReadAllLines(configFilePath);

            int lastCat = -1;

            for (int i = 0; i < lines.Length; i++)
            {
                switch (lines[i][0])
                {
                case '+':
                    //games.Add(new Game("", games.Count));
                    lastCat = -1;
                    Console.WriteLine("Add new item");
                    break;

                case '-':
                    string category = "";
                    string data     = "";
                    bool   result   = FileParser.ParseOption(lines[i], out category, out data);

                    if (result)
                    {
                        switch (category)
                        {
                        case "example":
                            //games[games.Count - 1].name = data;
                            Console.WriteLine("Add example categories");
                            break;

                        default:
                            NetworkEngine.WriteError("Category " + category + " not found, error in file on line " + (i + 1).ToString());
                            return(false);

                            break;
                        }
                        lastCat = -1;
                    }
                    else
                    {
                        switch (category)
                        {
                        case "example2":
                            //lastCat = 2;
                            Console.WriteLine("Add example categories with data in next line");
                            break;

                        default:
                            NetworkEngine.WriteError("Category " + category + " not found, error in file on line " + (i + 1).ToString());
                            return(false);

                            break;
                        }
                    }
                    break;

                default:
                    switch (lastCat)
                    {
                    case -1:
                        NetworkEngine.WriteError("Data without category ( " + lines[i] + " ) on line " + (i + 1).ToString());
                        return(false);

                        break;

                    default:
                        NetworkEngine.WriteError("Data without category ( " + lines[i] + " ) on line " + (i + 1).ToString());
                        return(false);

                        break;

                    case 2:
                        Console.WriteLine("Some example addings");
                        //users[users.Count - 1].Add(new User(line));
                        break;
                    }
                    break;
                }
            }

            return(true);
        }