示例#1
0
            public static bool Prefix(string saveFileName)
            {
                string fileName    = saveFileName;
                string fileContent = System.IO.File.ReadAllText(GenFilePaths.FilePathForSavedGame(saveFileName));

                if (SyncTickData.cliendID == 0)
                {
                    PirateRPC.PirateRPC.SendInvocation(NetDemo.ns, u =>
                    {
                        NetDemo.SetSFD(new NetDemo.SaveFileData()
                        {
                            tcontext = fileContent, partial_name = fileName + "_received"
                        });

                        PirateRPC.PirateRPC.SendInvocation(u, uu => { NetDemo.LoadFromRemoteSFD(); });
                    });

                    LongEventHandler.QueueLongEvent(() =>
                    {
                        for (; NetDemo.GetSFD() == null;)
                        {
                        }
                    }, "Downloading savefile".Translate(), true, e => { RimLog.Error(e.ToString()); });
                }

                return(false);
            }
示例#2
0
        public static void GenerateWorld()
        {
            ThingIDMakerPatch.stopID = true;

            ThinkTreeKeyAssigner.Reset();

            foreach (var def in DefDatabase <ThinkTreeDef> .AllDefsListForReading)
            {
                ThinkTreeKeyAssigner.AssignKeys(def.thinkRoot, 0);
            }


            if (SyncTickData.cliendID == 0)
            {
                Find.WindowStack.Add(new Dialog_SaveFileList_Load());
            }
            else
            {
                LongEventHandler.QueueLongEvent(() =>
                {
                    NetDemo.LoadFromRemoteSFD();
                    for (; NetDemo.GetSFD() == null;)
                    {
                    }
                }, "Downloading savefile".Translate(), true, e => { RimLog.Error(e.ToString()); });
            }
        }
示例#3
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);
                }
            }
        }
示例#4
0
    public static void WaitForConnection(string host)
    {
        tc = new TcpClient();
        tc.Client.NoDelay = true;
        tc.Connect(host, 12345);
        ns               = tc.GetStream();
        hasClientID      = false;
        forcedDisconnect = false;
        try
        {
            LongEventHandler.QueueLongEvent(() =>
            {
                PirateRPC.PirateRPC.SendInvocation(ns, u =>
                {
                    int cid = SyncTickData.cliendID;
                    Interlocked.Increment(ref SyncTickData.cliendID);
                    NetDemo.ServerHandlePlayerJoined(cid, u);
                });

                for (; !hasClientID && !forcedDisconnect;)
                {
                }
            }, "Waiting for server".Translate(), true, e => { RimLog.Error(e.ToString()); });
        }
        catch (Exception ee)
        {
            log(ee.ToString());
        }

        Thread t = new Thread(() =>
        {
            for (;  ;)
            {
                PirateRPC.PirateRPC.ReceiveInvocation(ns);
            }
        });

        t.Start();
    }