Пример #1
0
        public static bool FlushSyncTickData(int tickNum)
        {
            /*if (new System.Collections.ICollection[]
             * {
             *  singleton.jobsToSerialize,
             *  singleton.jobPriorities,
             *  singleton.designations,
             *  singleton.designatorCellCalls,
             *  singleton.designatorMultiCellCalls,
             *  singleton.ForbiddenCallDataCall
             * }.Any(u => { return u.Count > 0; }))*/
            {
                try
                {
#if FILE_TRANSFER
                    string s = @"D:\CoopReplays\_" + tickNum + "client_" + cliendID + ".xml";

                    //RimLog.Message("Written : " + s);
                    BinaryFormatter ser      = new BinaryFormatter();
                    var             fs       = System.IO.File.OpenWrite(s);
                    SyncTickData    buffered = singleton;
                    singleton = new SyncTickData();
                    ser.Serialize(fs, buffered);
                    fs.Flush();
                    fs.Close();
                    System.IO.File.WriteAllText(s + ".sync", "");
#else
                    if (cliendID > -1)
                    {
                        singleton.randomToVerify = new int[] { Verse.Rand.Int };
                        var colonists = Find.ColonistBar.GetColonistsInOrder();
                        singleton.colonistJobsToVerify     = colonists == null ? new List <string> {
                        } : colonists.ConvertAll <string>(u => u.CurJobDef == null ? u.ThingID + "::" + "<null>" : u.ThingID + "::" + u.CurJobDef.defName);
                        singleton.serializationServiceData = SerializationService.Flush();
                        BinaryFormatter ser = new BinaryFormatter()
                        {
                            TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded
                        };
                        SyncTickData buffered = singleton;
                        MemoryStream fs       = new MemoryStream();
                        singleton = new SyncTickData();
                        //RimLog.Message("sending data for tick " + tickNum);
                        NetDemo.PushStateToDirectory(cliendID, tickNum, buffered, 0);
                        fs.Close();
                        return(true);
                    }
                    return(false);
#endif
                }
                catch (Exception ee)
                {
                    RimLog.Error(ee.ToString());
                    return(false);
                }
            }
        }