コード例 #1
0
        protected virtual void parseDataMessageFromClient(NetIncomingMessage dataMsg)
        {
            NetConnection peer = dataMsg.SenderConnection;

            using (IncomingMessage message = new IncomingMessage())
            {
                using (NetBufferReadStream stream = new NetBufferReadStream(dataMsg))
                {
                    using (BinaryReader reader = new BinaryReader(stream))
                    {
                        while (dataMsg.LengthBits - dataMsg.Position >= 8)
                        {
                            message.Read(reader);
                            if (peers.ContainsLeft(message.FarmerID) && peers[message.FarmerID] == peer)
                            {
                                gameServer.processIncomingMessage(message);
                            }
                            else if (message.MessageType == 2)
                            {
                                NetFarmerRoot farmer = Game1.multiplayer.readFarmer(message.Reader);
                                gameServer.checkFarmhandRequest("", getConnectionId(dataMsg.SenderConnection), farmer, delegate(OutgoingMessage msg)
                                {
                                    sendMessage(peer, msg);
                                }, delegate
                                {
                                    peers[farmer.Value.UniqueMultiplayerID] = peer;
                                });
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void checkFarmhandRequest(string userID, string connectionID, NetFarmerRoot farmer, Action <OutgoingMessage> sendMessage, Action approve)
        {
            if (farmer.Value == null)
            {
                rejectFarmhandRequest(userID, farmer, sendMessage);
                return;
            }
            long   id    = farmer.Value.UniqueMultiplayerID;
            Action check = delegate
            {
                if (_pendingFarmhandSelections.ContainsKey(connectionID))
                {
                    _pendingFarmhandSelections.Remove(connectionID);
                }
                Farmer farmer2 = findOriginalFarmhand(farmer.Value);
                if (!isConnectionActive(connectionID))
                {
                    Console.WriteLine("Rejected request for connection ID " + connectionID + ": Connection not active.");
                }
                else if (farmer2 == null)
                {
                    Console.WriteLine("Rejected request for farmhand " + id + ": doesn't exist");
                    rejectFarmhandRequest(userID, farmer, sendMessage);
                }
                else if (!authCheck(userID, farmer2))
                {
                    Console.WriteLine("Rejected request for farmhand " + id + ": authorization failure");
                    rejectFarmhandRequest(userID, farmer, sendMessage);
                }
                else if ((Game1.otherFarmers.ContainsKey(id) && !Game1.multiplayer.isDisconnecting(id)) || Game1.serverHost.Value.UniqueMultiplayerID == id)
                {
                    Console.WriteLine("Rejected request for farmhand " + id + ": already in use");
                    rejectFarmhandRequest(userID, farmer, sendMessage);
                }
                else if (findCabin(farmer.Value).isInventoryOpen())
                {
                    Console.WriteLine("Rejected request for farmhand " + id + ": inventory in use");
                    rejectFarmhandRequest(userID, farmer, sendMessage);
                }
                else
                {
                    Console.WriteLine("Approved request for farmhand " + id);
                    approve();
                    Game1.updateCellarAssignments();
                    Game1.multiplayer.addPlayer(farmer);
                    Game1.multiplayer.broadcastPlayerIntroduction(farmer);
                    sendServerIntroduction(id);
                    updateLobbyData();
                }
            };

            if (!whenGameAvailable(check))
            {
                _pendingFarmhandSelections[connectionID] = check;
                Console.WriteLine("Postponing request for farmhand " + id + " from connection: " + connectionID);
                sendMessage(new OutgoingMessage(11, Game1.player, "Strings\\UI:Client_WaitForHostAvailability"));
            }
        }
コード例 #3
0
        protected virtual void receiveServerIntroduction(BinaryReader msg)
        {
            Game1.otherFarmers.Roots[Game1.player.UniqueMultiplayerID] = (Game1.player.NetFields.Root as NetFarmerRoot);
            NetFarmerRoot f  = Game1.multiplayer.readFarmer(msg);
            long          id = f.Value.UniqueMultiplayerID;

            Game1.serverHost = f;
            Game1.serverHost.Value.teamRoot = Game1.multiplayer.readObjectFull <FarmerTeam>(msg);
            Game1.otherFarmers.Roots.Add(id, f);
            Game1.player.teamRoot = Game1.serverHost.Value.teamRoot;
            Game1.netWorldState   = Game1.multiplayer.readObjectFull <IWorldState>(msg);
            Game1.netWorldState.Clock.InterpolationTicks = 0;
            Game1.netWorldState.Value.WriteToGame1();
            setUpGame();
            if (Game1.chatBox != null)
            {
                Game1.chatBox.listPlayers();
            }
        }
コード例 #4
0
        protected virtual void receiveAvailableFarmhands(BinaryReader msg)
        {
            int year       = msg.ReadInt32();
            int season     = msg.ReadInt32();
            int dayOfMonth = msg.ReadInt32();
            int count      = msg.ReadByte();

            availableFarmhands = new List <Farmer>();
            while (availableFarmhands.Count < count)
            {
                NetFarmerRoot netFarmerRoot = new NetFarmerRoot();
                netFarmerRoot.ReadFull(msg, default(NetVersion));
                netFarmerRoot.MarkReassigned();
                netFarmerRoot.MarkClean();
                Farmer farmhand = netFarmerRoot.Value;
                availableFarmhands.Add(farmhand);
                farmhand.yearForSaveGame       = year;
                farmhand.seasonForSaveGame     = season;
                farmhand.dayOfMonthForSaveGame = dayOfMonth;
            }
            hasHandshaked     = true;
            connectionMessage = null;
            if (Game1.activeClickableMenu is TitleMenu || Game1.activeClickableMenu is FarmhandMenu)
            {
                return;
            }
            using (List <Farmer> .Enumerator enumerator = availableFarmhands.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    Game1.player = enumerator.Current;
                    sendPlayerIntroduction();
                    return;
                }
            }
            Game1.multiplayer.Disconnect(Multiplayer.DisconnectType.ServerFull);
        }
コード例 #5
0
 private void rejectFarmhandRequest(string userID, NetFarmerRoot farmer, Action <OutgoingMessage> sendMessage)
 {
     sendAvailableFarmhands(userID, sendMessage);
     Console.WriteLine("Rejected request for farmhand " + ((farmer.Value != null) ? farmer.Value.UniqueMultiplayerID.ToString() : "???"));
 }