public bool Start() { //Setup the variable toggles varBindingsInitialize(); int tmpMaxPlayers = 16; // Read in from the config file. DatafileWriter dataFile = new DatafileWriter("server.config.txt"); if (dataFile.Data.ContainsKey("winningcash")) winningCashAmount = uint.Parse(dataFile.Data["winningcash"], System.Globalization.CultureInfo.InvariantCulture); if (dataFile.Data.ContainsKey("includelava")) includeLava = bool.Parse(dataFile.Data["includelava"]); if (dataFile.Data.ContainsKey("includewater")) includeLava = bool.Parse(dataFile.Data["includewater"]); if (dataFile.Data.ContainsKey("orefactor")) oreFactor = uint.Parse(dataFile.Data["orefactor"], System.Globalization.CultureInfo.InvariantCulture); if (dataFile.Data.ContainsKey("maxplayers")) tmpMaxPlayers = (int)Math.Min(32, uint.Parse(dataFile.Data["maxplayers"], System.Globalization.CultureInfo.InvariantCulture)); if (dataFile.Data.ContainsKey("public")) varSet("public", bool.Parse(dataFile.Data["public"]), true); if (dataFile.Data.ContainsKey("servername")) varSet("name", dataFile.Data["servername"], true); if (dataFile.Data.ContainsKey("sandbox")) varSet("sandbox", bool.Parse(dataFile.Data["sandbox"]), true); if (dataFile.Data.ContainsKey("notnt")) varSet("tnt", !bool.Parse(dataFile.Data["notnt"]), true); if (dataFile.Data.ContainsKey("sphericaltnt")) varSet("stnt", bool.Parse(dataFile.Data["sphericaltnt"]), true); if (dataFile.Data.ContainsKey("insane")) varSet("insane", bool.Parse(dataFile.Data["insane"]), true); if (dataFile.Data.ContainsKey("roadabsorbs")) varSet("roadabsorbs", bool.Parse(dataFile.Data["roadabsorbs"]), true); if (dataFile.Data.ContainsKey("minelava")) varSet("minelava", bool.Parse(dataFile.Data["minelava"]), true); if (dataFile.Data.ContainsKey("levelname")) levelToLoad = dataFile.Data["levelname"]; if (dataFile.Data.ContainsKey("greeter")) varSet("greeter", dataFile.Data["greeter"],true); bool autoannounce = true; if (dataFile.Data.ContainsKey("autoannounce")) autoannounce = bool.Parse(dataFile.Data["autoannounce"]); // Load the ban-list. banList = LoadBanList(); // Load the admin-list admins = LoadAdminList(); if (tmpMaxPlayers>=0) varSet("maxplayers", tmpMaxPlayers, true); // Initialize the server. NetConfiguration netConfig = new NetConfiguration("InfiniminerPlus"); netConfig.MaxConnections = (int)varGetI("maxplayers"); netConfig.Port = 5565; netServer = new InfiniminerNetServer(netConfig); netServer.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true); //netServer.SimulatedMinimumLatency = 0.5f; // netServer.SimulatedLatencyVariance = 0.05f; // netServer.SimulatedLoss = 0.2f; // netServer.SimulatedDuplicates = 0.05f; //netServer.Configuration.SendBufferSize = 2048000; //netServer.Start();//starts too early // Initialize variables we'll use. NetBuffer msgBuffer = netServer.CreateBuffer(); NetMessageType msgType; NetConnection msgSender; // Store the last time that we did a flow calculation. DateTime lastFlowCalc = DateTime.Now; DateTime lastFlowCalcZ = DateTime.Now;//temporary DateTime sysTimer = DateTime.Now; //Check if we should autoload a level if (dataFile.Data.ContainsKey("autoload") && bool.Parse(dataFile.Data["autoload"])) { blockList = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE]; blockCreatorTeam = new PlayerTeam[MAPSIZE, MAPSIZE, MAPSIZE]; LoadLevel(levelToLoad); lavaBlockCount = 0; waterBlockCount = 0; int burstBlockCount = 0; for (ushort i = 0; i < MAPSIZE; i++) for (ushort j = 0; j < MAPSIZE; j++) for (ushort k = 0; k < MAPSIZE; k++) { if (blockList[i, j, k] == BlockType.Lava) { lavaBlockCount += 1; } else if (blockList[i, j, k] == BlockType.Water) { waterBlockCount += 1; } else if (blockList[i, j, k] == BlockType.MagmaBurst) { burstBlockCount += 1; } } ConsoleWrite(waterBlockCount + " water blocks, " + lavaBlockCount + " lava blocks, " + burstBlockCount + " possible bursts." ); } else { // Calculate initial lava flows. ConsoleWrite("CALCULATING INITIAL LIQUID BLOCKS"); newMap(); lavaBlockCount = 0; waterBlockCount = 0; int burstBlockCount = 0; for (ushort i = 0; i < MAPSIZE; i++) for (ushort j = 0; j < MAPSIZE; j++) for (ushort k = 0; k < MAPSIZE; k++) { if (blockList[i, j, k] == BlockType.Lava) { lavaBlockCount += 1; } else if (blockList[i, j, k] == BlockType.Water) { waterBlockCount += 1; } else if (blockList[i, j, k] == BlockType.MagmaBurst) { burstBlockCount += 1; } } ConsoleWrite(waterBlockCount + " water blocks, " + lavaBlockCount + " lava blocks, " + burstBlockCount + " possible bursts."); } //Caculate the shape of spherical tnt explosions CalculateExplosionPattern(); // Send the initial server list update. if (autoannounce) PublicServerListUpdate(true); lastMapBackup = DateTime.Now; DateTime lastFPScheck = DateTime.Now; double frameRate = 0; // Main server loop! netServer.Start(); ConsoleWrite("SERVER READY"); if (!physics.IsAlive) { ConsoleWrite("Physics thread is limp."); } while (keepRunning) { if (!physics.IsAlive) { ConsoleWrite("Physics thread died."); // physics.Abort(); // physics.Join(); //physics.Start(); } frameCount = frameCount + 1; if (lastFPScheck <= DateTime.Now - TimeSpan.FromMilliseconds(1000)) { lastFPScheck = DateTime.Now; frameRate = frameCount;// / gameTime.ElapsedTotalTime.TotalSeconds; if (sleeping == false && frameCount < 20) { ConsoleWrite("Heavy load: " + frameCount + " FPS"); } frameCount = 0; } // Process any messages that are here. while (netServer.ReadMessage(msgBuffer, out msgType, out msgSender)) { try { switch (msgType) { case NetMessageType.ConnectionApproval: { Player newPlayer = new Player(msgSender, null); newPlayer.Handle = Defines.Sanitize(msgBuffer.ReadString()).Trim(); if (newPlayer.Handle.Length == 0) { newPlayer.Handle = "Player"; } string clientVersion = msgBuffer.ReadString(); if (clientVersion != Defines.INFINIMINER_VERSION) { msgSender.Disapprove("VER;" + Defines.INFINIMINER_VERSION); } else if (banList.Contains(newPlayer.IP)) { msgSender.Disapprove("BAN;"); }/* else if (playerList.Count == maxPlayers) { msgSender.Disapprove("FULL;"); }*/ else { if (admins.ContainsKey(newPlayer.IP)) newPlayer.admin = admins[newPlayer.IP]; playerList[msgSender] = newPlayer; //Check if we should compress the map for the client try { bool compression = msgBuffer.ReadBoolean(); if (compression) playerList[msgSender].compression = true; } catch { } toGreet.Add(msgSender); this.netServer.SanityCheck(msgSender); msgSender.Approve(); PublicServerListUpdate(true); } } break; case NetMessageType.StatusChanged: { if (!this.playerList.ContainsKey(msgSender)) { break; } Player player = playerList[msgSender]; if (msgSender.Status == NetConnectionStatus.Connected) { if (sleeping == true) { sleeping = false; physicsEnabled = true; } ConsoleWrite("CONNECT: " + playerList[msgSender].Handle + " ( " + playerList[msgSender].IP + " )"); SendCurrentMap(msgSender); SendPlayerJoined(player); PublicServerListUpdate(); } else if (msgSender.Status == NetConnectionStatus.Disconnected) { ConsoleWrite("DISCONNECT: " + playerList[msgSender].Handle); SendPlayerLeft(player, player.Kicked ? "WAS KICKED FROM THE GAME!" : "HAS ABANDONED THEIR DUTIES!"); if (playerList.ContainsKey(msgSender)) playerList.Remove(msgSender); sleeping = true; foreach (Player p in playerList.Values) { sleeping = false; } if (sleeping == true) { ConsoleWrite("HIBERNATING"); physicsEnabled = false; } PublicServerListUpdate(); } } break; case NetMessageType.Data: { if (!this.playerList.ContainsKey(msgSender)) { break; } Player player = playerList[msgSender]; InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte(); switch (dataType) { case InfiniminerMessage.ChatMessage: { // Read the data from the packet. ChatMessageType chatType = (ChatMessageType)msgBuffer.ReadByte(); string chatString = Defines.Sanitize(msgBuffer.ReadString()); if (!ProcessCommand(chatString,GetAdmin(playerList[msgSender].IP),playerList[msgSender])) { if (chatType == ChatMessageType.SayAll) ConsoleWrite("CHAT: (" + player.Handle + ") " + chatString); // Append identifier information. if (chatType == ChatMessageType.SayAll) chatString = player.Handle + " (ALL): " + chatString; else chatString = player.Handle + " (TEAM): " + chatString; // Construct the message packet. NetBuffer chatPacket = netServer.CreateBuffer(); chatPacket.Write((byte)InfiniminerMessage.ChatMessage); chatPacket.Write((byte)((player.Team == PlayerTeam.Red) ? ChatMessageType.SayRedTeam : ChatMessageType.SayBlueTeam)); chatPacket.Write(chatString); // Send the packet to people who should recieve it. foreach (Player p in playerList.Values) { if (chatType == ChatMessageType.SayAll || chatType == ChatMessageType.SayBlueTeam && p.Team == PlayerTeam.Blue || chatType == ChatMessageType.SayRedTeam && p.Team == PlayerTeam.Red) if (p.NetConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(chatPacket, p.NetConn, NetChannel.ReliableInOrder3); } } } break; case InfiniminerMessage.UseTool: { Vector3 playerPosition = msgBuffer.ReadVector3(); Vector3 playerHeading = msgBuffer.ReadVector3(); PlayerTools playerTool = (PlayerTools)msgBuffer.ReadByte(); BlockType blockType = (BlockType)msgBuffer.ReadByte(); //getTo switch (playerTool) { case PlayerTools.Pickaxe: UsePickaxe(player, playerPosition, playerHeading); break; case PlayerTools.StrongArm: if (player.Class == PlayerClass.Miner) UseStrongArm(player, playerPosition, playerHeading); break; case PlayerTools.Smash: //if(player.Class == PlayerClass.Sapper) //UseSmash(player, playerPosition, playerHeading); break; case PlayerTools.ConstructionGun: UseConstructionGun(player, playerPosition, playerHeading, blockType); break; case PlayerTools.DeconstructionGun: UseDeconstructionGun(player, playerPosition, playerHeading); break; case PlayerTools.ProspectingRadar: UseSignPainter(player, playerPosition, playerHeading); break; case PlayerTools.Detonator: if (player.Class == PlayerClass.Sapper) UseDetonator(player); break; case PlayerTools.Remote: if (player.Class == PlayerClass.Engineer) UseRemote(player); break; case PlayerTools.SetRemote: if (player.Class == PlayerClass.Engineer) SetRemote(player); break; case PlayerTools.ThrowBomb: if (player.Class == PlayerClass.Sapper) ThrowBomb(player, playerPosition, playerHeading); break; case PlayerTools.ThrowRope: if (player.Class == PlayerClass.Prospector) ThrowRope(player, playerPosition, playerHeading); break; case PlayerTools.Hide: if (player.Class == PlayerClass.Prospector) Hide(player); break; } } break; case InfiniminerMessage.SelectClass: { PlayerClass playerClass = (PlayerClass)msgBuffer.ReadByte(); player.Alive = false; ConsoleWrite("SELECT_CLASS: " + player.Handle + ", " + playerClass.ToString()); switch (playerClass) { case PlayerClass.Engineer: player.Class = playerClass; player.OreMax = 200 + (uint)(ResearchComplete[(byte)player.Team, 2] * 20); player.WeightMax = 4 + (uint)(ResearchComplete[(byte)player.Team, 2]); player.HealthMax = 100 + (uint)(ResearchComplete[(byte)player.Team,1]*20); player.Health = player.HealthMax; for (int a = 0; a < 100; a++) { player.Content[a] = 0; } break; case PlayerClass.Miner://strong arm/throws blocks player.Class = playerClass; player.OreMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 2] * 20); player.WeightMax = 10 + (uint)(ResearchComplete[(byte)player.Team, 2]); player.HealthMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 1] * 20); player.Health = player.HealthMax; for (int a = 0; a < 100; a++) { player.Content[a] = 0; } break; case PlayerClass.Prospector://profiteer/has prospectron/stealth/climb/traps player.Class = playerClass; player.OreMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 2] * 20); player.WeightMax = 6 + (uint)(ResearchComplete[(byte)player.Team, 2]); player.HealthMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 1] * 20); player.Health = player.HealthMax; for (int a = 0; a < 100; a++) { player.Content[a] = 0; } break; case PlayerClass.Sapper://berserker/charge that knocks people and blocks away/repairs block player.Class = playerClass; player.OreMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 2] * 20); player.WeightMax = 4 + (uint)(ResearchComplete[(byte)player.Team, 2]); player.HealthMax = 100 + (uint)(ResearchComplete[(byte)player.Team, 1] * 20); player.Health = player.HealthMax; for (int a = 0; a < 100; a++) { player.Content[a] = 0; } break; } SendResourceUpdate(player); SendContentUpdate(player); SendPlayerSetClass(player); } break; case InfiniminerMessage.PlayerSetTeam: { PlayerTeam playerTeam = (PlayerTeam)msgBuffer.ReadByte(); ConsoleWrite("SELECT_TEAM: " + player.Handle + ", " + playerTeam.ToString()); player.Team = playerTeam; player.Health = 0; player.Alive = false; Player_Dead(player, ""); SendResourceUpdate(player); SendPlayerSetTeam(player); } break; case InfiniminerMessage.PlayerDead: { string deathMessage = msgBuffer.ReadString(); if (player.Alive) { Player_Dead(player, deathMessage); } } break; case InfiniminerMessage.PlayerAlive: { if (toGreet.Contains(msgSender)) { string greeting = varGetS("greeter"); greeting = greeting.Replace("[name]", playerList[msgSender].Handle); if (greeting != "") { NetBuffer greetBuffer = netServer.CreateBuffer(); greetBuffer.Write((byte)InfiniminerMessage.ChatMessage); greetBuffer.Write((byte)ChatMessageType.SayAll); greetBuffer.Write(Defines.Sanitize(greeting)); netServer.SendMessage(greetBuffer, msgSender, NetChannel.ReliableInOrder3); } toGreet.Remove(msgSender); } ConsoleWrite("PLAYER_ALIVE: " + player.Handle); player.Ore = 0; player.Cash = 0; player.Weight = 0; player.Health = player.HealthMax; player.Alive = true; player.respawnTimer = DateTime.Now + TimeSpan.FromSeconds(5); SendResourceUpdate(player); SendPlayerAlive(player); } break; case InfiniminerMessage.PlayerRespawn: { SendPlayerRespawn(player);//new respawn } break; case InfiniminerMessage.PlayerUpdate: { if (player.Alive) { player.Position = Auth_Position(msgBuffer.ReadVector3(), player, true); player.Heading = Auth_Heading(msgBuffer.ReadVector3()); player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); SendPlayerUpdate(player); } } break; case InfiniminerMessage.PlayerSlap: { if (player.Alive) { if (player.playerToolCooldown > DateTime.Now) { break;//discard fast packet } player.Position = Auth_Position(msgBuffer.ReadVector3(), player, true); player.Heading = Auth_Heading(msgBuffer.ReadVector3()); player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = true; Auth_Slap(player, msgBuffer.ReadUInt32()); SendPlayerUpdate(player); player.playerToolCooldown = DateTime.Now + TimeSpan.FromSeconds((float)(player.GetToolCooldown(PlayerTools.Pickaxe))); if (player.Class == PlayerClass.Prospector && player.Content[5] > 0)//reveal when hit { player.Content[6] = 0;//uncharge player.Content[1] = 0;//reappear on radar SendPlayerContentUpdate(player, 1); player.Content[5] = 0;//sight SendContentSpecificUpdate(player, 5); SendContentSpecificUpdate(player, 6); SendPlayerContentUpdate(player, 5); SendServerMessageToPlayer("You have been revealed!", player.NetConn); EffectAtPoint(player.Position - Vector3.UnitY * 1.5f, 1); } } } break; case InfiniminerMessage.PlayerUpdate1://minus position { if (player.Alive) { player.Heading = Auth_Heading(msgBuffer.ReadVector3()); player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); SendPlayerUpdate(player); } } break; case InfiniminerMessage.PlayerUpdate2://minus position and heading { if (player.Alive) { player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); SendPlayerUpdate(player); } } break; case InfiniminerMessage.PlayerHurt://client speaks of fall damage { uint newhp = msgBuffer.ReadUInt32(); if (newhp < player.Health) { if (player.Team == PlayerTeam.Red) { DebrisEffectAtPoint((int)(player.Position.X), (int)(player.Position.Y), (int)(player.Position.Z), BlockType.SolidRed, 10 + (int)(player.Health - newhp)); } else { DebrisEffectAtPoint((int)(player.Position.X), (int)(player.Position.Y), (int)(player.Position.Z), BlockType.SolidBlue, 10 + (int)(player.Health - newhp)); } player.Health = newhp; if (player.Health < 1) { Player_Dead(player, "FELL TO THEIR DEATH!"); } } } break; case InfiniminerMessage.PlayerPosition://server not interested in clients complaints about position { } break; case InfiniminerMessage.PlayerInteract://client speaks of mashing on block { player.Position = Auth_Position(msgBuffer.ReadVector3(), player, true); uint btn = msgBuffer.ReadUInt32(); uint btnx = msgBuffer.ReadUInt32(); uint btny = msgBuffer.ReadUInt32(); uint btnz = msgBuffer.ReadUInt32(); //if (blockList[btnx, btny, btnz] == BlockType.Pump || blockList[btnx, btny, btnz] == BlockType.Pipe || blockList[btnx, btny, btnz] == BlockType.Generator || blockList[btnx, btny, btnz] == BlockType.Barrel || blockList[btnx, btny, btnz] == BlockType.Switch) //{ if (Get3DDistance((int)btnx, (int)btny, (int)btnz, (int)player.Position.X, (int)player.Position.Y, (int)player.Position.Z) < 4) { PlayerInteract(player,btn, btnx, btny, btnz); } //} } break; case InfiniminerMessage.DepositOre: { DepositOre(player); foreach (Player p in playerList.Values) SendResourceUpdate(p); } break; case InfiniminerMessage.WithdrawOre: { WithdrawOre(player); foreach (Player p in playerList.Values) SendResourceUpdate(p); } break; case InfiniminerMessage.PlayerPing: { if (player.Ping == 0) { SendPlayerPing((uint)msgBuffer.ReadInt32()); player.Ping = 2; } } break; case InfiniminerMessage.PlaySound: { InfiniminerSound sound = (InfiniminerSound)msgBuffer.ReadByte(); Vector3 position = msgBuffer.ReadVector3(); PlaySoundForEveryoneElse(sound, position,player); } break; case InfiniminerMessage.DropItem: { DropItem(player, msgBuffer.ReadUInt32()); } break; case InfiniminerMessage.GetItem: { //verify players position before get player.Position = Auth_Position(msgBuffer.ReadVector3(), player, false); GetItem(player,msgBuffer.ReadUInt32()); } break; } } break; } } catch { } } //Time to backup map? TimeSpan mapUpdateTimeSpan = DateTime.Now - lastMapBackup; if (mapUpdateTimeSpan.TotalMinutes > 5) { lastMapBackup = DateTime.Now; SaveLevel("autoBK.lvl"); } // Time to send a new server update? PublicServerListUpdate(); //It checks for public server / time span //Time to terminate finished map sending threads? TerminateFinishedThreads(); // Check for players who are in the zone to deposit. VictoryCheck(); // Is it time to do a lava calculation? If so, do it! TimeSpan timeSpan = DateTime.Now - sysTimer; if (timeSpan.TotalMilliseconds > 2000) { //ConsoleWrite("" + delta); sysTimer = DateTime.Now; //secondflow += 1; //if (secondflow > 2)//every 2nd flow, remove the vacuum that prevent re-spread //{ // EraseVacuum(); // secondflow = 0; //} if (randGen.Next(1, 4) == 3) { bool isUpdateOre = false; bool isUpdateCash = false; for (int a = 1; a < 3; a++) { if (artifactActive[a, 1] > 0)//material artifact { isUpdateOre = true; if (a == 1) { teamOreRed = teamOreRed + (uint)(10 * artifactActive[a, 1]); } else if (a == 2) { teamOreBlue = teamOreBlue + (uint)(10 * artifactActive[a, 1]); } } if (artifactActive[a, 5] > 0)//golden artifact { isUpdateCash = true; if (a == 1) { teamCashRed = teamCashRed + (uint)(2 * artifactActive[a, 5]); } else if (a == 2) { teamCashBlue = teamCashBlue + (uint)(2 * artifactActive[a, 5]); } } } if (isUpdateOre) foreach (Player p in playerList.Values) SendTeamOreUpdate(p); if(isUpdateCash) foreach (Player p in playerList.Values) SendTeamCashUpdate(p); } foreach (Player p in playerList.Values)//regeneration { if (p.Ping > 0) p.Ping--; if (p.Alive) { if (p.Content[10] == 1)//material artifact personal { if (randGen.Next(1, 4) == 3) { if (p.Ore < p.OreMax) { p.Ore += 10; if (p.Ore >= p.OreMax) p.Ore = p.OreMax; SendOreUpdate(p); } } } else if (p.Content[10] == 5)//golden artifact personal { if (p.Ore > 99) { if (p.Weight < p.WeightMax) { p.Weight++; p.Cash += 10; p.Ore -= 100; SendCashUpdate(p); SendWeightUpdate(p); SendOreUpdate(p); PlaySound(InfiniminerSound.CashDeposit, p.Position); } } } else if (p.Content[10] == 6)//storm artifact personal { if(artifactActive[(byte)((p.Team == PlayerTeam.Red) ? PlayerTeam.Blue : PlayerTeam.Red),6] == 0)//stored storm artifact makes team immune foreach (Player pt in playerList.Values) { if (p.Team != pt.Team && pt.Alive) { float distfromPlayer = (p.Position - pt.Position).Length(); if (distfromPlayer < 5) { pt.Health -= 5; if (pt.Health <= 0) { Player_Dead(pt,"WAS SHOCKED!"); } else SendHealthUpdate(pt); EffectAtPoint(pt.Position, 1); } } } } if (p.Health >= p.HealthMax) { p.Health = p.HealthMax; } else { p.Health = (uint)(p.Health + teamRegeneration[(byte)p.Team]); if (p.Content[10] == 3)//regeneration artifact { p.Health += 4; } if (p.Health >= p.HealthMax) { p.Health = p.HealthMax; } SendHealthUpdate(p); } if (p.Class == PlayerClass.Prospector) { if (p.Content[5] == 1) { p.Content[6]--; if (p.Content[6] < 1) { p.Content[1] = 0; SendPlayerContentUpdate(p, 1); p.Content[5] = 0;//sight SendContentSpecificUpdate(p, 5); SendPlayerContentUpdate(p, 5); SendServerMessageToPlayer("Hide must now recharge!", p.NetConn); EffectAtPoint(p.Position - Vector3.UnitY * 1.5f, 1); } } else { if(p.Content[6] < 4) p.Content[6]++; } } //if (p.Class == PlayerClass.Prospector)//temperature data//giving everyone //{ // p.Content[6] = 0; // for(int a = -5;a < 6;a++) // for(int b = -5;b < 6;b++) // for (int c = -5; c < 6; c++) // { // int nx = a + (int)p.Position.X; // int ny = b + (int)p.Position.Y; // int nz = c + (int)p.Position.Z; // if (nx < MAPSIZE - 1 && ny < MAPSIZE - 1 && nz < MAPSIZE - 1 && nx > 0 && ny > 0 && nz > 0) // { // BlockType block = blockList[nx,ny,nz]; // if (block == BlockType.Lava || block == BlockType.MagmaBurst || block == BlockType.MagmaVent) // { // p.Content[6] += 5 - Math.Abs(a) + 5 - Math.Abs(b) + 5 - Math.Abs(c); // } // } // } // if (p.Content[6] > 0) // SendContentSpecificUpdate(p, 6); //} } } } TimeSpan timeSpanZ = DateTime.Now - lastFlowCalcZ; serverTime[timeQueue] = DateTime.Now - lastTime;//timeQueue timeQueue += 1; if (timeQueue > 19) timeQueue = 0; lastTime = DateTime.Now; delta = (float)((serverTime[0].TotalSeconds + serverTime[1].TotalSeconds + serverTime[2].TotalSeconds + serverTime[3].TotalSeconds + serverTime[4].TotalSeconds + serverTime[5].TotalSeconds + serverTime[6].TotalSeconds + serverTime[7].TotalSeconds + serverTime[8].TotalSeconds + serverTime[9].TotalSeconds + serverTime[10].TotalSeconds + serverTime[11].TotalSeconds + serverTime[12].TotalSeconds + serverTime[13].TotalSeconds + serverTime[14].TotalSeconds + serverTime[15].TotalSeconds + serverTime[16].TotalSeconds + serverTime[17].TotalSeconds + serverTime[18].TotalSeconds + serverTime[19].TotalSeconds) / 20); Sunray(); if (timeSpanZ.TotalMilliseconds > 50) { lastFlowCalcZ = DateTime.Now; DoItems(); } //random diamond appearance if (sleeping == false) if (randGen.Next(1, 100000) == 2) { ushort diamondx = (ushort)randGen.Next(4, 57); ushort diamondy = (ushort)randGen.Next(3, 30); ushort diamondz = (ushort)randGen.Next(4, 57); if (blockList[diamondx, diamondy, diamondz] == BlockType.Dirt) { // ConsoleWrite("diamond spawned at " + diamondx + "/" + diamondy + "/" + diamondz); SetBlock(diamondx, diamondy, diamondz, BlockType.Diamond, PlayerTeam.None); blockListHP[diamondx, diamondy, diamondz] = BlockInformation.GetMaxHP(BlockType.Diamond); } } // Handle console keypresses. while (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) { if (consoleInput.Length > 0) ConsoleProcessInput(); } else if (keyInfo.Key == ConsoleKey.Backspace) { if (consoleInput.Length > 0) consoleInput = consoleInput.Substring(0, consoleInput.Length - 1); ConsoleRedraw(); } else { consoleInput += keyInfo.KeyChar; ConsoleRedraw(); } } // Is the game over? if (winningTeam != PlayerTeam.None && !restartTriggered) { BroadcastGameOver(); restartTriggered = true; restartTime = DateTime.Now.AddSeconds(10); } // Restart the server? if (restartTriggered && DateTime.Now > restartTime) { SaveLevel("autosave_" + (UInt64)DateTime.Now.ToBinary() + ".lvl"); netServer.Shutdown("The server is restarting."); Thread.Sleep(100); physics.Abort(); // mechanics.Abort(); return true;//terminates server thread completely } // Pass control over to waiting threads. if(sleeping == true) { Thread.Sleep(50); } else { Thread.Sleep(1); } } MessageAll("Server going down NOW!"); netServer.Shutdown("The server was terminated."); return false; }
/*************** // Start of mods for detecting client mods ***************/ // Checks the players speed over last 10 updates and trys to figure out if they are above expected speed - DCaudill public bool CheckSpeed(Player player) { // Calculate expected max avg distance double maxDistance = 0; for (int i = 0; i < player.positionList.Count; i++) { Vector3 footPosition = player.positionList[i].position + new Vector3(0f, -1.5f, 0f); BlockType standingOnBlock = BlockAtPoint(new Vector3(footPosition.X, footPosition.Y, footPosition.Z)); if (standingOnBlock == BlockType.Road) maxDistance += .5; else maxDistance += .3; } maxDistance = maxDistance / player.positionList.Count; // Calculate the players avg distance double distance = 0; bool oddDistance = false; for (int i = 0; i < player.positionList.Count; i++) { if (player.positionList[i].distanceFromLast > .3 && !oddDistance) { oddDistance = true; continue; } distance += player.positionList[i].distanceFromLast; } distance = distance / player.positionList.Count; if (distance > maxDistance) return true; else return false; }
public void DepositCash(Player player) { if (player.Cash <= 0) return; player.Score += player.Cash; if (!varGetB("sandbox")) { if (player.Team == PlayerTeam.Red) teamCashRed += player.Cash; else teamCashBlue += player.Cash; SendServerMessage("SERVER: " + player.Handle + " HAS EARNED $" + player.Cash + " FOR THE " + GetTeamName(player.Team) + " TEAM!"); } PlaySound(InfiniminerSound.CashDeposit, player.Position); ConsoleWrite("DEPOSIT_CASH: " + player.Handle + ", " + player.Cash); player.Cash = 0; player.Weight = 0; foreach (Player p in playerList.Values) SendResourceUpdate(p); }
public void UseDeconstructionGun(Player player, Vector3 playerPosition, Vector3 playerHeading) { bool actionFailed = false; // If there's no surface within range, bail. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint)) actionFailed = true; ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; // If this is another team's block, bail. if (blockCreatorTeam[x, y, z] != player.Team) actionFailed = true; BlockType blockType = blockList[x, y, z]; if (!(blockType == BlockType.SolidBlue || blockType == BlockType.SolidRed || blockType == BlockType.BankBlue || blockType == BlockType.BankRed || blockType == BlockType.Jump || blockType == BlockType.Ladder || blockType == BlockType.Road || blockType == BlockType.Shock || blockType == BlockType.BeaconRed || blockType == BlockType.BeaconBlue || blockType == BlockType.TransBlue || blockType == BlockType.TransRed)) actionFailed = true; if (actionFailed) { // Decharge the player's gun. TriggerConstructionGunAnimation(player, -0.2f); } else { // Fire the player's gun. TriggerConstructionGunAnimation(player, 0.5f); // Remove the block. SetBlock(x, y, z, BlockType.None, PlayerTeam.None); PlaySound(InfiniminerSound.ConstructionGun, player.Position); } }
public void UsePickaxe(Player player, Vector3 playerPosition, Vector3 playerHeading) { player.QueueAnimationBreak = true; // Figure out what we're hitting. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint)) return; ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; // Figure out what the result is. bool removeBlock = false; uint giveOre = 0; uint giveCash = 0; uint giveWeight = 0; InfiniminerSound sound = InfiniminerSound.DigDirt; switch (BlockAtPoint(hitPoint)) { case BlockType.Lava: if (varGetB("minelava")) { removeBlock = true; sound = InfiniminerSound.DigDirt; } break; case BlockType.Dirt: case BlockType.DirtSign: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.Ore: removeBlock = true; giveOre = 20; sound = InfiniminerSound.DigMetal; break; case BlockType.Gold: removeBlock = true; giveWeight = 1; giveCash = 100; sound = InfiniminerSound.DigMetal; break; case BlockType.Diamond: removeBlock = true; giveWeight = 1; giveCash = 1000; sound = InfiniminerSound.DigMetal; break; } if (giveOre > 0) { if (player.Ore < player.OreMax) { player.Ore = Math.Min(player.Ore + giveOre, player.OreMax); SendResourceUpdate(player); } } if (giveWeight > 0) { if (player.Weight < player.WeightMax) { player.Weight = Math.Min(player.Weight + giveWeight, player.WeightMax); player.Cash += giveCash; SendResourceUpdate(player); } else removeBlock = false; } if (removeBlock) { SetBlock(x, y, z, BlockType.None, PlayerTeam.None); PlaySound(sound, player.Position); } }
// Checks to see if the player has 4 consecutive no clipping flags - DCaudill public bool CheckNoClipping(Player player) { int counter = 0; for (int i = 0; i < player.positionList.Count; i++) { if (BlockAtPoint(player.positionList[i].position) != BlockType.None && BlockAtPoint(player.positionList[i].position) != BlockType.TransBlue && BlockAtPoint(player.positionList[i].position) != BlockType.TransRed && BlockAtPoint(player.positionList[i].position) != BlockType.Lava) { counter++; if (counter > 4) return true; } else counter = 0; } return false; }
public void TriggerConstructionGunAnimation(Player player, float animationValue) { if (player.NetConn.Status != NetConnectionStatus.Connected) return; // ore, cash, weight, max ore, max weight, team ore, red cash, blue cash, all uint NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.TriggerConstructionGunAnimation); msgBuffer.Write(animationValue); netServer.SendMessage(msgBuffer, player.NetConn, NetChannel.ReliableInOrder1); }
public void UseRemote(Player player) { if (player.Content[5] > 0) { PlayerInteract(player, (uint)(player.Content[5]), (uint)(player.Content[6]), (uint)(player.Content[7]), (uint)(player.Content[8])); } else { SendServerMessageToPlayer("Remote is not attached to anything.", player.NetConn); } }
public void UseSmash(Player player, Vector3 playerPosition, Vector3 playerHeading) { }
public void UseDeconstructionGun(Player player, Vector3 playerPosition, Vector3 playerHeading) { bool actionFailed = false; // If there's no surface within range, bail. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint, BlockType.Water)) actionFailed = true; ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; // If this is another team's block, bail. if (blockCreatorTeam[x, y, z] != player.Team) actionFailed = true; BlockType blockType = blockList[x, y, z]; if (!(blockType == BlockType.SolidBlue || blockType == BlockType.SolidRed || blockType == BlockType.SolidBlue2 || blockType == BlockType.SolidRed2 || blockType == BlockType.BankBlue || blockType == BlockType.BankRed || blockType == BlockType.ArtCaseR || blockType == BlockType.ArtCaseB || blockType == BlockType.Jump || blockType == BlockType.Ladder || blockType == BlockType.Road || blockType == BlockType.Shock || blockType == BlockType.ResearchR || blockType == BlockType.ResearchB || blockType == BlockType.BeaconRed || blockType == BlockType.BeaconBlue || blockType == BlockType.Water || blockType == BlockType.TransBlue || blockType == BlockType.TransRed || blockType == BlockType.GlassR || blockType == BlockType.GlassB || blockType == BlockType.Generator || blockType == BlockType.Pipe || blockType == BlockType.Pump || blockType == BlockType.RadarBlue || blockType == BlockType.RadarRed || blockType == BlockType.Barrel || blockType == BlockType.Hinge || blockType == BlockType.Lever || blockType == BlockType.Plate || blockType == BlockType.Controller || blockType == BlockType.Water || blockType == BlockType.StealthBlockB || blockType == BlockType.StealthBlockR || blockType == BlockType.TrapB || blockType == BlockType.TrapR )) actionFailed = true; if (actionFailed) { // Decharge the player's gun. TriggerConstructionGunAnimation(player, -0.2f); } else { // Fire the player's gun. TriggerConstructionGunAnimation(player, 0.5f); if (blockType == BlockType.RadarRed)//requires special remove { foreach (Player p in playerList.Values) { if (p.Alive && p.Team == PlayerTeam.Blue) { if (p.Content[1] == 1) { p.Content[1] = 0;//goes off radar again SendPlayerContentUpdate(p, 1); } } } } else if (blockType == BlockType.RadarBlue)//requires special remove { foreach (Player p in playerList.Values) { if (p.Alive && p.Team == PlayerTeam.Red) { if (p.Content[1] == 1) { p.Content[1] = 0;//goes off radar again SendPlayerContentUpdate(p, 1); } } } } else if (blockType == BlockType.ConstructionR || blockType == BlockType.ConstructionB) { if (blockListContent[x, y, z, 0] == (byte)BlockType.ArtCaseR || blockListContent[x, y, z, 0] == (byte)BlockType.ArtCaseB) { if (y < MAPSIZE - 1) if (blockList[x, y + 1, z] == BlockType.Vacuum) blockList[x, y + 1, z] = BlockType.None;//restore vacuum to normal } } else if (blockType == BlockType.ArtCaseR || blockType == BlockType.ArtCaseB) { if (y < MAPSIZE - 1) if (blockList[x, y + 1, z] == BlockType.ForceR || blockList[x, y + 1, z] == BlockType.ForceB) { SetBlock(x, (ushort)(y + 1), z, BlockType.None, PlayerTeam.None);//remove field } if (blockListContent[x, y, z, 6] > 0) { uint arty = (uint)(blockListContent[x, y, z, 6]); itemList[arty].Content[6] = 0;//unlock arty SendItemContentSpecificUpdate(itemList[(uint)(blockListContent[x, y, z, 6])], 6); if (blockList[x, y, z] == BlockType.ArtCaseB) { teamArtifactsBlue--; SendScoreUpdate(); } else if (blockList[x, y, z] == BlockType.ArtCaseR) { teamArtifactsRed--; SendScoreUpdate(); } } } // Remove the block. SetBlock(x, y, z, BlockType.None, PlayerTeam.None); PlaySound(InfiniminerSound.ConstructionGun, player.Position); } }
public void UsePickaxe(Player player, Vector3 playerPosition, Vector3 playerHeading) { player.QueueAnimationBreak = true; // Figure out what we're hitting. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (artifactActive[(byte)player.Team, 4] > 0 || player.Content[10] == 4) { if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint, BlockType.Water)) { //ConsoleWrite(player.Handle + " lost a block sync."); return; } } else { if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint, BlockType.None)) { //ConsoleWrite(player.Handle + " lost a block sync."); return; } } ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; if (player.Alive == false || player.playerToolCooldown > DateTime.Now) { //ConsoleWrite("fixed " + player.Handle + " synchronization"); SetBlockForPlayer(x, y, z, blockList[x, y, z], blockCreatorTeam[x, y, z], player); return; } else { player.playerToolCooldown = DateTime.Now + TimeSpan.FromSeconds((float)(player.GetToolCooldown(PlayerTools.Pickaxe))); } // Figure out what the result is. bool removeBlock = false; uint giveOre = 0; uint giveCash = 0; uint giveWeight = 0; int Damage = 2 + ResearchComplete[(byte)player.Team, 5]; InfiniminerSound sound = InfiniminerSound.DigDirt; BlockType block = BlockAtPoint(hitPoint); switch (block) { case BlockType.Lava: if (varGetB("minelava")) { removeBlock = true; sound = InfiniminerSound.DigDirt; } break; case BlockType.Water: if (varGetB("minelava")) { removeBlock = true; sound = InfiniminerSound.DigDirt; } break; case BlockType.Dirt: case BlockType.Mud: case BlockType.Grass: case BlockType.Sand: case BlockType.DirtSign: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.StealthBlockB: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.StealthBlockR: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.TrapB: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.TrapR: removeBlock = true; sound = InfiniminerSound.DigDirt; break; case BlockType.Ore: removeBlock = true; giveOre = 20; sound = InfiniminerSound.DigMetal; break; case BlockType.Gold: Damage = 2; giveWeight = 1; giveCash = 10; sound = InfiniminerSound.DigMetal; break; case BlockType.Diamond: //removeBlock = true; //giveWeight = 1; //giveCash = 1000; sound = InfiniminerSound.DigMetal; break; case BlockType.SolidRed: case BlockType.SolidBlue: case BlockType.SolidRed2: case BlockType.SolidBlue2: sound = InfiniminerSound.DigMetal; break; default: break; } if (giveOre > 0) { if (player.Ore < player.OreMax - giveOre) { player.Ore += giveOre; SendOreUpdate(player); } else if(player.Ore < player.OreMax)//vaporize some ore to fit into players inventory { player.Ore = player.OreMax; SendOreUpdate(player); } else//ore goes onto ground { SetItem(ItemType.Ore, hitPoint - (playerHeading * 0.3f), playerHeading, new Vector3(playerHeading.X * 1.5f, 0.0f, playerHeading.Z * 1.5f), PlayerTeam.None, 0); } } if (giveWeight > 0) { if (player.Weight < player.WeightMax) { player.Weight = Math.Min(player.Weight + giveWeight, player.WeightMax); player.Cash += giveCash; SendWeightUpdate(player); SendCashUpdate(player); } else { removeBlock = false; if (block == BlockType.Gold) { if (player.Weight == player.WeightMax) { //gold goes onto the ground SetItem(ItemType.Gold, hitPoint, playerHeading, new Vector3(playerHeading.X * 1.5f, 0.0f, playerHeading.Z * 1.5f), PlayerTeam.None, 0); } } } } if (removeBlock)//block falls away with any hit { //SetBlock(x, y, z, BlockType.None, PlayerTeam.None); SetBlockDebris(x, y, z, BlockType.None, PlayerTeam.None);//blockset + adds debris for all players PlaySoundForEveryoneElse(sound, player.Position, player); } else if (Damage > 0 && BlockInformation.GetMaxHP(block) > 0)//this block is resistant to pickaxes { if (blockCreatorTeam[x, y, z] != player.Team)//block does not belong to us: destroy it { if (blockListHP[x, y, z] < Damage) { if(block == BlockType.RadarRed) { foreach (Player p in playerList.Values) { if (p.Alive && p.Team == PlayerTeam.Blue) { if (p.Content[1] == 1) { p.Content[1] = 0;//goes off radar again SendPlayerContentUpdate(p, 1); } } } } else if(block == BlockType.RadarBlue) { foreach (Player p in playerList.Values) { if (p.Alive && p.Team == PlayerTeam.Red) { if (p.Content[1] == 1) { p.Content[1] = 0;//goes off radar again SendPlayerContentUpdate(p, 1); } } } } else if (block == BlockType.ArtCaseR || block == BlockType.ArtCaseB) { if (y < MAPSIZE - 1) if (blockList[x, y + 1, z] == BlockType.ForceR || blockList[x, y + 1, z] == BlockType.ForceB) { SetBlock(x, (ushort)(y + 1), z, BlockType.None, PlayerTeam.None); } if (blockListContent[x, y, z, 6] > 0) { uint arty = (uint)(blockListContent[x, y, z, 6]); itemList[arty].Content[6] = 0;//unlock arty SendItemContentSpecificUpdate(itemList[(uint)(blockListContent[x, y, z, 6])], 6); if (blockList[x, y, z] == BlockType.ArtCaseR) ArtifactTeamBonus(PlayerTeam.Red, itemList[arty].Content[10], false); else if (blockList[x, y, z] == BlockType.ArtCaseB) ArtifactTeamBonus(PlayerTeam.Blue, itemList[arty].Content[10], false); if (blockList[x, y, z] == BlockType.ArtCaseB) { teamArtifactsBlue--; SendScoreUpdate(); } else if (blockList[x, y, z] == BlockType.ArtCaseR) { teamArtifactsRed--; SendScoreUpdate(); } } NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ChatMessage); if(block == BlockType.ArtCaseB) msgBuffer.Write((byte)ChatMessageType.SayBlueTeam); else if(block == BlockType.ArtCaseR) msgBuffer.Write((byte)ChatMessageType.SayRedTeam); msgBuffer.Write(Defines.Sanitize("The enemy team has destroyed one of our artifact safehouses!")); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) if (playerList[netConn].Team == PlayerTeam.Red && block == BlockType.ArtCaseR) { netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered); } else if (playerList[netConn].Team == PlayerTeam.Blue && block == BlockType.ArtCaseB) { netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered); } } else if (block == BlockType.Diamond) { uint piece = SetItem(ItemType.Diamond, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), Vector3.Zero, Vector3.Zero, PlayerTeam.None, 0); } SetBlockDebris(x, y, z, BlockType.None, PlayerTeam.None);//blockset + adds debris for all players blockListHP[x, y, z] = 0; sound = InfiniminerSound.Explosion; } else { hitPoint -= playerHeading * 0.3f; DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0); blockListHP[x, y, z] -= Damage; hitPoint -= (playerHeading*0.4f); if (block == BlockType.SolidRed2 || block == BlockType.SolidBlue2) { if (blockListHP[x, y, z] < 21) { SetBlock(x, y, z, blockCreatorTeam[x, y, z] == PlayerTeam.Red ? BlockType.SolidRed : BlockType.SolidBlue, blockCreatorTeam[x, y, z]); } } else if (block == BlockType.Gold) { PlaySoundForEveryoneElse(InfiniminerSound.RadarLow, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), player); //InfiniminerSound.RadarHigh } else if (block == BlockType.Diamond) { PlaySoundForEveryoneElse(InfiniminerSound.RadarHigh, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), player); } if (artifactActive[(byte)blockCreatorTeam[x, y, z], 7] > 0)//reflection artifact { if (player.Health > 2 * artifactActive[(byte)blockCreatorTeam[x, y, z], 7]) { player.Health -= (uint)(2 * artifactActive[(byte)blockCreatorTeam[x, y, z], 7]); SendHealthUpdate(player); } else { Player_Dead(player, "BEAT THEMSELVES AGAINST A WALL!"); } } } PlaySoundForEveryoneElse(sound, player.Position, player); } else { if (player.Ore > ResearchComplete[(byte)player.Team, 4])//make repairs { Damage = -(2 * ResearchComplete[(byte)player.Team, 4] + 2); //sound = repair? if (blockListHP[x, y, z] >= BlockInformation.GetMaxHP(blockList[x, y, z])) { if (block == BlockType.SolidRed || block == BlockType.SolidBlue) { hitPoint -= playerHeading * 0.3f; player.Ore -= (uint)ResearchComplete[(byte)player.Team, 4] + 1; blockListHP[x, y, z] -= Damage; DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0); SetBlock(x, y, z, player.Team == PlayerTeam.Red ? BlockType.SolidRed2 : BlockType.SolidBlue2, player.Team); SendOreUpdate(player); PlaySoundForEveryoneElse(sound, player.Position, player); } else if (block == BlockType.ConstructionR && player.Team == PlayerTeam.Red || block == BlockType.ConstructionB && player.Team == PlayerTeam.Blue)//construction complete { SetBlock(x, (ushort)(y + 1), z, player.Team == PlayerTeam.Red ? BlockType.ForceR : BlockType.ForceB, player.Team); SetBlock(x, y, z, (BlockType)blockListContent[x,y,z,0], player.Team); blockListHP[x, y, z] = BlockInformation.GetMaxHP(blockList[x, y, z]); } } else { hitPoint -= playerHeading * 0.3f; player.Ore -= (uint)ResearchComplete[(byte)player.Team, 4] + 1; DebrisEffectAtPoint(hitPoint.X, hitPoint.Y, hitPoint.Z, block, 0); blockListHP[x, y, z] -= Damage; SendOreUpdate(player); PlaySoundForEveryoneElse(sound, player.Position, player); } } } } else {//player was out of sync, replace his empty block //ConsoleWrite("fixed " + player.Handle + " synchronization"); SetBlockForPlayer(x, y, z, block, blockCreatorTeam[x, y, z], player); } }
public void UseConstructionGun(Player player, Vector3 playerPosition, Vector3 playerHeading, BlockType blockType) { bool actionFailed = false; bool constructionRequired = false; // If there's no surface within range, bail. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint,BlockType.Water)) actionFailed = true; // If the block is too expensive, bail. uint blockCost = BlockInformation.GetCost(blockType); if (varGetB("sandbox") && blockCost <= player.OreMax) blockCost = 0; if (blockCost > player.Ore) actionFailed = true; if (!allowBlock[(byte)player.Team, (byte)player.Class, (byte)blockType]) actionFailed = true; // If there's someone there currently, bail. ushort x = (ushort)buildPoint.X; ushort y = (ushort)buildPoint.Y; ushort z = (ushort)buildPoint.Z; foreach (Player p in playerList.Values) { if ((int)p.Position.X == x && (int)p.Position.Z == z && ((int)p.Position.Y == y || (int)p.Position.Y - 1 == y)) actionFailed = true; } // If it's out of bounds, bail. if (x <= 0 || y <= 0 || z <= 0 || (int)x > MAPSIZE - 1 || (int)y >= MAPSIZE - 1 || (int)z > MAPSIZE - 1)//y >= prevent blocks going too high on server actionFailed = true; // If it's near a base, bail. //if (LocationNearBase(x, y, z)) // actionFailed = true; // If it's lava, don't let them build off of lava. if (blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Lava || blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Water) actionFailed = true; if(!actionFailed) if (blockType == BlockType.ArtCaseR || blockType == BlockType.ArtCaseB) {//space above must be cleared constructionRequired = true; //if (blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y + 1, (ushort)hitPoint.Z] != BlockType.None) //{ // actionFailed = true; //} //else //{ // SetBlock(x, (ushort)(y+1), z, BlockType.Vacuum, player.Team);//space for artifact //} } if (actionFailed) { // Decharge the player's gun. TriggerConstructionGunAnimation(player, -0.2f); } else { // Fire the player's gun. TriggerConstructionGunAnimation(player, 0.5f); // Build the block. // if (blockType == BlockType.Lava) //blockType = BlockType.Fire; if (constructionRequired == true)//block changes into construction block with blocktype on content[0] { if (blockType == BlockType.ArtCaseR || blockType == BlockType.ArtCaseB) { //check above for space if (blockList[x, y+1, z] == BlockType.None) { blockList[x, y+1, z] = BlockType.Vacuum;//player cant see, dont bother updating for client } else { return;//wasnt space for the glass } } if (player.Team == PlayerTeam.Red) { SetBlock(x, y, z, BlockType.ConstructionR, player.Team); } else if (player.Team == PlayerTeam.Blue) { SetBlock(x, y, z, BlockType.ConstructionB, player.Team); } blockListHP[x, y, z] = BlockInformation.GetHP(blockType);//base block hp blockListContent[x, y, z, 0] = (byte)blockType; if (blockType == BlockType.ArtCaseR || blockType == BlockType.ArtCaseB) { blockListContent[x, y, z, 6] = 0; } } else { if(blockType == BlockType.Metal) SetBlock(x, y, z, blockType, PlayerTeam.None); else SetBlock(x, y, z, blockType, player.Team); if (BlockInformation.GetMaxHP(blockType) > 0) { blockListHP[x, y, z] = BlockInformation.GetHP(blockType);//base block hp } } player.Ore -= blockCost; SendOreUpdate(player); //SendResourceUpdate(player); // Play the sound. PlaySound(InfiniminerSound.ConstructionGun, player.Position); // If it's an explosive block, add it to our list. if (blockType == BlockType.Explosive) player.ExplosiveList.Add(new Vector3(x,y,z) ); } }
public bool Trigger(int x, int y, int z, int ox, int oy, int oz, int btn, Player player) { //if object can be manipulated by levers, it should always return true if the link should remain persistent //if the Trigger function returns false, it will remove the link if (player != null) if (player.Content[2] > 0)//player is attempting to link something { if (player.Content[9] == 1 && player.Class == PlayerClass.Engineer) { if (x > 0 && x < MAPSIZE - 1 && y > 0 && y < MAPSIZE - 1 && z > 0 && z < MAPSIZE - 1) { if (blockList[x, y, z] == BlockType.ResearchB || blockList[x, y, z] == BlockType.ResearchR || blockList[x, y, z] == BlockType.BaseBlue || blockList[x, y, z] == BlockType.BaseRed || blockList[x, y, z] == BlockType.ArtCaseR || blockList[x, y, z] == BlockType.ArtCaseB || blockList[x, y, z] == BlockType.BankRed || blockList[x, y, z] == BlockType.BankBlue) { player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; player.Content[5] = 0; player.Content[9] = 0; SendServerMessageToPlayer("The remote cannot function on " + blockList[x, y, z] + ".", player.NetConn); } else { player.Content[5] = (int)btn; player.Content[6] = (int)x; player.Content[7] = (int)y; player.Content[8] = (int)z; player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; //player.Content[5] = 0; SendServerMessageToPlayer("Linked remote to action " + btn + " on " + blockList[x, y, z] + ".", player.NetConn); player.Content[9] = 0; } return true; } } if (x == player.Content[2] && y == player.Content[3] && z == player.Content[4]) { player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); SendServerMessageToPlayer("Cancelled link.", player.NetConn); return true; } int freeslot = 9; int nb = 0; for (nb = 2; nb < 7; nb++) { if (blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 1] == x && blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 2] == y && blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 3] == z) { blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6] = 0; blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 1] = 0; blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 2] = 0; blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 3] = 0; blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 4] = 0;//unlinked player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); SendServerMessageToPlayer(blockList[x, y, z] + " was unlinked.", player.NetConn); return true; } else if (blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6] == 0 && freeslot == 9) { freeslot = nb; break;//makes sure that we arent reattaching links over and over } } if (freeslot == 9) return false; if (nb != 7)//didnt hit end of switch-link limit {//should check teams and connection to itself //range check if (Distf(new Vector3(x, y, z), new Vector3(player.Content[2], player.Content[3], player.Content[4])) < 10) { //Vector3 heading = new Vector3(player.Content[2], player.Content[3], player.Content[4]); //heading -= new Vector3(x, y, z); //heading.Normalize(); //if (RayCollision(new Vector3(x, y, z) + heading * 0.4f, heading, (float)(Distf(new Vector3(x, y, z), new Vector3(player.Content[2], player.Content[3], player.Content[4]))), 10, blockList[x, y, z])) //{ blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 1] = (int)(x); blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 2] = (int)(y); blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 3] = (int)(z); blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6 + 4] = (int)(btn); blockListContent[player.Content[2], player.Content[3], player.Content[4], nb * 6] = 100; SendServerMessageToPlayer(blockList[player.Content[2], player.Content[3], player.Content[4]] + " linked action " + btn + " on " + blockList[x, y, z] + ".", player.NetConn); //} //else //{ // SendServerMessageToPlayer(blockList[player.Content[2], player.Content[3], player.Content[4]] + " was not in line of sight of " + blockList[x, y, z] + " to link!", player.NetConn); //} } else { SendServerMessageToPlayer(blockList[player.Content[2], player.Content[3], player.Content[4]] + " was too far away from the " + blockList[x, y, z] + " to link!", player.NetConn); } player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } else { SendServerMessageToPlayer("Lever is too overloaded to link more objects.", player.NetConn); player.Content[2] = 0; player.Content[3] = 0; player.Content[4] = 0; SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } return true; } //beginning of trigger actions if (blockList[x, y, z] == BlockType.Pipe) { ConsoleWrite("Chain connected to src:" + blockListContent[x, y, z, 1] + " src: " + blockListContent[x, y, z, 2] + " dest: " + blockListContent[x, y, z, 4] + " Connections: " + blockListContent[x, y, z, 3]); } else if (blockList[x, y, z] == BlockType.BeaconRed || blockList[x, y, z] == BlockType.BeaconBlue) { if (player != null) { if (btn == 1) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.BeaconRed || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.BeaconBlue) { } } } } else if (blockList[x, y, z] == BlockType.ResearchR || blockList[x, y, z] == BlockType.ResearchB) { if (player != null) { if (btn == 1) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.ResearchR || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.ResearchB) { if (blockListContent[x, y, z, 0] == 0) { blockListContent[x, y, z, 0]++; SendServerMessageToPlayer("Research has begun.", player.NetConn); } else { blockListContent[x, y, z, 0]--; SendServerMessageToPlayer("Research paused.", player.NetConn); } } } else if (btn == 2) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.ResearchR || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.ResearchB) { if (blockListContent[x, y, z, 1] < (byte)Research.MAXIMUM-1) { blockListContent[x, y, z, 0] = 0; blockListContent[x, y, z, 1]++; SendServerMessageToPlayer("Research topic:" + ResearchInformation.GetName((Research)blockListContent[x, y, z, 1]) + "(" + ResearchComplete[(byte)player.Team, blockListContent[x, y, z, 1]] + ") (" + ResearchProgress[(byte)player.Team, blockListContent[x, y, z, 1]] + " gold)", player.NetConn); // blockListContent[x, y, z, 2] = ResearchInformation.GetCost((Research)blockListContent[x, y, z, 1]); } else { blockListContent[x, y, z, 0] = 0; blockListContent[x, y, z, 1] = 1; SendServerMessageToPlayer("Research topic:" + ResearchInformation.GetName((Research)blockListContent[x, y, z, 1]) + "(" + ResearchComplete[(byte)player.Team, blockListContent[x, y, z, 1]] + ") (" + ResearchProgress[(byte)player.Team, blockListContent[x, y, z, 1]] + " gold)", player.NetConn); } } } } } else if (blockList[x, y, z] == BlockType.ArtCaseR || blockList[x, y, z] == BlockType.ArtCaseB) { if (player != null) { if (btn == 1) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.ArtCaseR || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.ArtCaseB) if (player.Content[10] > 0 && blockListContent[x, y, z, 6] == 0) {//place artifact uint arty = SetItem(ItemType.Artifact, new Vector3(x + 0.5f, y + 1.5f, z + 0.5f), Vector3.Zero, Vector3.Zero, player.Team, player.Content[10]); itemList[arty].Content[6] = 1;//lock artifact in place blockListContent[x, y, z, 6] = (int)(arty); player.Content[10] = 0; SendItemContentSpecificUpdate(itemList[arty], 6);//lock item SendContentSpecificUpdate(player, 10);//inform players SendPlayerContentUpdate(player, 10);//inform activator ArtifactTeamBonus(player.Team, itemList[arty].Content[10], true); if (blockList[x, y, z] == BlockType.ArtCaseB) { teamArtifactsBlue++; SendScoreUpdate(); } else if (blockList[x, y, z] == BlockType.ArtCaseR) { teamArtifactsRed++; SendScoreUpdate(); } } } else if (btn == 2) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.ArtCaseR || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.ArtCaseB) if (player.Content[10] == 0 && blockListContent[x, y, z, 6] > 0) {//retrieve artifact uint arty = (uint)(blockListContent[x, y, z, 6]); itemList[arty].Content[6] = 0;//unlock artifact in place blockListContent[x, y, z, 6] = 0;//artcase empty player.Content[10] = itemList[arty].Content[10];//player is holding the new artifact itemList[arty].Disposing = true;//item gets removed SendContentSpecificUpdate(player, 10);//inform players SendPlayerContentUpdate(player, 10);//inform activator ArtifactTeamBonus(player.Team, itemList[arty].Content[10], false); if (blockList[x, y, z] == BlockType.ArtCaseB) { teamArtifactsBlue--; SendScoreUpdate(); } else if (blockList[x, y, z] == BlockType.ArtCaseR) { teamArtifactsRed--; SendScoreUpdate(); } } } } return true; } else if (blockList[x, y, z] == BlockType.BaseBlue || blockList[x, y, z] == BlockType.BaseRed) { if (player != null) { if (btn == 1) { if (player.Team == PlayerTeam.Red && blockList[x, y, z] == BlockType.BaseRed || player.Team == PlayerTeam.Blue && blockList[x, y, z] == BlockType.BaseBlue) //if (player.Content[11] > 0 && blockListContent[x, y, z, 1] == 0) {//begin forge // player.Content[11]--; // player.Weight--; //requirement turned off for now SendWeightUpdate(player); SendContentSpecificUpdate(player, 11); blockListContent[x, y, z, 1] = artifactCost; NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ChatMessage); if (player.Team == PlayerTeam.Red) msgBuffer.Write((byte)ChatMessageType.SayRedTeam); else if (player.Team == PlayerTeam.Blue) msgBuffer.Write((byte)ChatMessageType.SayBlueTeam); msgBuffer.Write(Defines.Sanitize("The " + player.Team + " has begun forging an artifact!")); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered); } } else if (btn == 2) { } } return true; } else if (blockList[x, y, z] == BlockType.Lever) { if (btn == 1) { if (player != null) SendServerMessageToPlayer("You pull the lever!", player.NetConn); if (blockListContent[x, y, z, 0] == 0)//not falling { for (int a = 2; a < 7; a++) { if (blockListContent[x, y, z, a * 6] > 0) { int bx = blockListContent[x, y, z, a * 6 + 1]; int by = blockListContent[x, y, z, a * 6 + 2]; int bz = blockListContent[x, y, z, a * 6 + 3]; int bbtn = blockListContent[x, y, z, a * 6 + 4]; if (Trigger(bx, by, bz, x, y, z, bbtn, null) == false) { //trigger returned no result, delete the link blockListContent[x, y, z, a * 6] = 0; blockListContent[x, y, z, a * 6 + 1] = 0; blockListContent[x, y, z, a * 6 + 2] = 0; blockListContent[x, y, z, a * 6 + 3] = 0; blockListContent[x, y, z, a * 6 + 4] = 0; } } } } } else if (btn == 2) { if (player != null)//only a player can invoke this action { int nb = 0; for (nb = 2; nb < 7; nb++) { if (blockListContent[x, y, z, nb * 6] == 0) { break; } } if (nb != 7)//didnt hit end of switch-link limit { SendServerMessageToPlayer("You are now linking objects.", player.NetConn); player.Content[2] = (int)(x);//player is creating a link to this switch player.Content[3] = (int)(y); player.Content[4] = (int)(z); SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } else { SendServerMessageToPlayer("This lever is overloaded, you are now unlinking objects.", player.NetConn); player.Content[2] = (int)(x);//player is creating a link to this switch player.Content[3] = (int)(y); player.Content[4] = (int)(z); SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } } } return true; } else if (blockList[x, y, z] == BlockType.Plate) { if (btn == 1) { // if (player != null) // SendServerMessageToPlayer("You stand on a pressure plate!", player.NetConn); if (blockListContent[x, y, z, 0] == 0 && blockListContent[x, y, z, 1] < 1)//not falling and recharged { if (player != null) blockListContent[x, y, z, 1] = blockListContent[x, y, z, 2];//only players will trigger the timer for (int a = 2; a < 7; a++) { if (blockListContent[x, y, z, a * 6] > 0) { int bx = blockListContent[x, y, z, a * 6 + 1]; int by = blockListContent[x, y, z, a * 6 + 2]; int bz = blockListContent[x, y, z, a * 6 + 3]; int bbtn = blockListContent[x, y, z, a * 6 + 4]; if (Trigger(bx, by, bz, x, y, z, bbtn, null) == false) { //trigger returned no result, delete the link blockListContent[x, y, z, a * 6] = 0; blockListContent[x, y, z, a * 6 + 1] = 0; blockListContent[x, y, z, a * 6 + 2] = 0; blockListContent[x, y, z, a * 6 + 3] = 0; blockListContent[x, y, z, a * 6 + 4] = 0; } } } } } else if (btn == 2) { if (player != null)//only a player can invoke this action { int nb = 0; for (nb = 2; nb < 7; nb++) { if (blockListContent[x, y, z, nb * 6] == 0) { break; } } if (nb != 7)//didnt hit end of switch-link limit { SendServerMessageToPlayer("You are now linking objects.", player.NetConn); player.Content[2] = (int)(x);//player is creating a link to this switch player.Content[3] = (int)(y); player.Content[4] = (int)(z); SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } else { SendServerMessageToPlayer("This lever is overloaded, you are now unlinking objects.", player.NetConn); player.Content[2] = (int)(x);//player is creating a link to this switch player.Content[3] = (int)(y); player.Content[4] = (int)(z); SendContentSpecificUpdate(player, 2); SendContentSpecificUpdate(player, 3); SendContentSpecificUpdate(player, 4); } } } else if (btn == 3) { if (blockListContent[x, y, z, 2] > 1) { blockListContent[x, y, z, 2] -= 1;//decrease retrigger timer if (player != null) SendServerMessageToPlayer("The pressure plate retrigger decreased to " + (blockListContent[x, y, z, 2] * 400) + " milliseconds.", player.NetConn); } else { blockListContent[x, y, z, 2] = 0; SendServerMessageToPlayer("The pressure plate now only retriggers when touched.", player.NetConn); } } else if (btn == 4) { blockListContent[x, y, z, 2] += 1;//increase retrigger timer if (player != null) SendServerMessageToPlayer("The pressure plate retrigger increased to " + (blockListContent[x, y, z, 2] * 400) + " milliseconds.", player.NetConn); } return true; } else if (blockList[x, y, z] == BlockType.Pump) { if (btn == 1) { if (blockListContent[x, y, z, 0] == 0) { if (player != null) SendServerMessageToPlayer(blockList[x, y, z] + " activated.", player.NetConn); blockListContent[x, y, z, 0] = 1; } else { if (player != null) SendServerMessageToPlayer(blockList[x, y, z] + " deactivated.", player.NetConn); blockListContent[x, y, z, 0] = 0; } } else if (btn == 2) { if (blockListContent[x, y, z, 1] < 5)//rotate { blockListContent[x, y, z, 1] += 1; if (player != null) SendServerMessageToPlayer(blockList[x, y, z] + " rotated to " + blockListContent[x, y, z, 1], player.NetConn); if (blockListContent[x, y, z, 1] == 1) { blockListContent[x, y, z, 2] = 0;//x input blockListContent[x, y, z, 3] = -1;//y input blockListContent[x, y, z, 4] = 0;//z input blockListContent[x, y, z, 5] = 1;//x output blockListContent[x, y, z, 6] = 0;//y output blockListContent[x, y, z, 7] = 0;//z output //pulls from below, pumps to side } else if (blockListContent[x, y, z, 1] == 2) { blockListContent[x, y, z, 2] = 0;//x input blockListContent[x, y, z, 3] = -1;//y input blockListContent[x, y, z, 4] = 0;//z input blockListContent[x, y, z, 5] = -1;//x output blockListContent[x, y, z, 6] = 0;//y output blockListContent[x, y, z, 7] = 0;//z output //pulls from below, pumps to otherside } else if (blockListContent[x, y, z, 1] == 3) { blockListContent[x, y, z, 2] = 0;//x input blockListContent[x, y, z, 3] = -1;//y input blockListContent[x, y, z, 4] = 0;//z input blockListContent[x, y, z, 5] = 0;//x output blockListContent[x, y, z, 6] = 0;//y output blockListContent[x, y, z, 7] = 1;//z output //pulls from below, pumps to otherside } else if (blockListContent[x, y, z, 1] == 4) { blockListContent[x, y, z, 2] = 0;//x input blockListContent[x, y, z, 3] = -1;//y input blockListContent[x, y, z, 4] = 0;//z input blockListContent[x, y, z, 5] = 0;//x output blockListContent[x, y, z, 6] = 0;//y output blockListContent[x, y, z, 7] = -1;//z output //pulls from below, pumps to otherside } } else { blockListContent[x, y, z, 1] = 0;//reset rotation if (player != null) SendServerMessageToPlayer(blockList[x, y, z] + " rotated to " + blockListContent[x, y, z, 1], player.NetConn); blockListContent[x, y, z, 2] = 0;//x input blockListContent[x, y, z, 3] = -1;//y input blockListContent[x, y, z, 4] = 0;//z input blockListContent[x, y, z, 5] = 0;//x output blockListContent[x, y, z, 6] = 1;//y output blockListContent[x, y, z, 7] = 0;//z output //pulls from below, pumps straight up } } return true; } else if (blockList[x, y, z] == BlockType.Barrel) { if (btn == 1) { if (blockListContent[x, y, z, 0] == 0) { if (player != null) SendServerMessageToPlayer("Filling..", player.NetConn); blockListContent[x, y, z, 0] = 1; } else { if (player != null) SendServerMessageToPlayer("Emptying..", player.NetConn); blockListContent[x, y, z, 0] = 0; } } else if (btn == 2) { } return true; } else if (blockList[x, y, z] == BlockType.Hinge) { if (btn == 1) { bool repairme = false; if (player != null) SendServerMessageToPlayer("You attempt to work the hinge!", player.NetConn); if (blockListContent[x, y, z, 0] == 0)//not falling { bool green = true; //blockListContent[x, y, z, 2] = 0; // blockListContent[x, y, z, 2] = 0;// +x // blockListContent[x, y, z, 2] = 2;// -x for (int a = 2; a < 7; a++) { //if (blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]] == (BlockType)(blockListContent[x, y, z, a * 6])) //{ if (HingeBlockTypes(blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]])) { } else { blockListContent[x, y, z, a * 6] = 0; blockListContent[x, y, z, a * 6 + 1] = 0; blockListContent[x, y, z, a * 6 + 2] = 0; blockListContent[x, y, z, a * 6 + 3] = 0; break; } if (blockListContent[x, y, z, a * 6] > 0) { int bx = blockListContent[x, y, z, a * 6 + 1]; int by = blockListContent[x, y, z, a * 6 + 2]; int bz = blockListContent[x, y, z, a * 6 + 3]; int relx = bx - x; int rely = by - y; int relz = bz - z; BlockType block = BlockType.Pipe; int mod = 1; if (blockListContent[x, y, z, 2] == 2 || blockListContent[x, y, z, 2] == 4)//-x & -z { mod = -1; } if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] < 3)//+x -> +y//checking upwards clear { //if (player != null) //SendServerMessageToPlayer("gc +-x +y", player.NetConn); //diagonal block = blockList[x + rely, y + relx, z + relz];//x + rely * (a - 1), y + relx * (a - 1), z + relz * (a - 1)]; block = blockList[x, y + (relx * mod), z];//relx*mod } else if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] > 2)//+z -> +y//checking upwards clear { //if (player != null) //SendServerMessageToPlayer("gc +-z +y", player.NetConn); block = blockList[x, y + (relz * mod), z];//relx*mod } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 0)//+y -> +x { //if (player != null) //SendServerMessageToPlayer("gc +y +x",player.NetConn); block = blockList[x + rely, y, z]; } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 2)//+y -> -x { //if (player != null) //SendServerMessageToPlayer("gc +y -x", player.NetConn); block = blockList[x - rely, y, z]; } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 3)//+y -> +z { //if (player != null) //SendServerMessageToPlayer("gc +y +z", player.NetConn); block = blockList[x, y, z + rely]; } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 4)//+y -> -z { //if (player != null) //SendServerMessageToPlayer("gc +y -z", player.NetConn); block = blockList[x, y, z - rely]; } if (block != BlockType.None && block != BlockType.Water && block != BlockType.Lava) { green = false;//obstruction //if (player != null) //{ // if (blockListContent[x, y, z, 1] != 1 && blockListContent[x, y, z, 2] == 0) // SendServerMessageToPlayer("not clear +x +y:" + (a - 1) + " " + blockList[x, y + (relx * mod), z], player.NetConn); // if (blockListContent[x, y, z, 1] != 1 && blockListContent[x, y, z, 2] == 2) // SendServerMessageToPlayer("not clear -x +y:" + (a - 1) + " " + blockList[x, y + (relx * mod), z], player.NetConn); // else if (blockListContent[x, y, z, 2] == 3) // SendServerMessageToPlayer("not clear y+z:" + (a - 1) + " " + blockList[x, y, z + rely], player.NetConn); // else if (blockListContent[x, y, z, 2] == 4) // SendServerMessageToPlayer("not clear y-z:" + (a - 1) + " " + blockList[x, y, z - rely], player.NetConn); // else if (blockListContent[x, y, z, 2] == 2) // SendServerMessageToPlayer("not clear y-x:" + (a - 1) + " " + blockList[x-rely, y, z], player.NetConn); // else // SendServerMessageToPlayer("not clear y+x:" + (a - 1) + " " + blockList[x+rely, y, z], player.NetConn); //} } } } if (repairme == false) { } else { if (player != null) SendServerMessageToPlayer("Hinge requires repair.", player.NetConn); } if (repairme == false) if (green == true) { for (int a = 2; a < 7; a++)//7 { if (blockListContent[x, y, z, a * 6] > 0) { if (repairme == false) if (HingeBlockTypes(blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]])) { int bx = blockListContent[x, y, z, a * 6 + 1];//data of block about to move int by = blockListContent[x, y, z, a * 6 + 2]; int bz = blockListContent[x, y, z, a * 6 + 3]; int relx = 0; int rely = 0; int relz = 0; if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] == 0)// +x -> +y { relx = bx - x; rely = 0; relz = 0; SetBlock((ushort)(x), (ushort)(by + relx), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, by + relx, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y + a - 1, z]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y + a - 1; blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green +x +y", player.NetConn); } else if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] == 3)// +z -> +y { relx = 0; rely = 0; relz = bz - z; SetBlock((ushort)(x), (ushort)(by + relz), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, by + relz, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y + a - 1, z]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y + a - 1; blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green +z +y", player.NetConn); } else if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] == 2)// -x -> +y { relx = bx - x; rely = 0; relz = 0; SetBlock((ushort)(x), (ushort)(by - relx), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, by - relx, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y + (a - 1), z]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y + (a - 1); blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green -x +y", player.NetConn); } else if (blockListContent[x, y, z, 1] == 1 && blockListContent[x, y, z, 2] == 4)// -z -> +y { relx = 0; rely = 0; relz = bz - z; SetBlock((ushort)(x), (ushort)(by - relz), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, by - relz, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y + (a - 1), z]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y + (a - 1); blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green -z +y", player.NetConn); } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 0)// +y -> +x { relx = 0; rely = by - y; relz = 0; if (blockList[bx + rely, y, z] == BlockType.Water || blockList[bx + rely, y, z] == BlockType.Lava) {//water in our way if (blockList[bx + rely, y + 1, z] == BlockType.None) {//push water up one SetBlock((ushort)(bx + rely), (ushort)(y + 1), (ushort)(z), blockList[bx + rely, y, z], PlayerTeam.None); blockListContent[bx + rely, y + 1, z, 1] = blockListContent[bx + rely, y, z, 1];//copy temperature blockListContent[bx + rely, y + 1, z, 2] = blockListContent[bx + rely, y, z, 2];//copy blocks future type } } SetBlock((ushort)(bx + rely), (ushort)(y), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[bx + rely, y, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x + a - 1, y, z]; blockListContent[x, y, z, a * 6 + 1] = x + a - 1; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green +y +x", player.NetConn); } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 3)// +y -> +z { relx = 0; rely = by - y; relz = 0; if (blockList[x, y, bz + rely] == BlockType.Water || blockList[x, y, bz + rely] == BlockType.Lava) {//water in our way if (blockList[x, y + 1, bz + rely] == BlockType.None) {//push water up one SetBlock((ushort)(x), (ushort)(y + 1), (ushort)(bz + rely), blockList[x, y, bz + rely], PlayerTeam.None); blockListContent[x, y + 1, bz + rely, 1] = blockListContent[x, y, bz + rely, 1];//copy temperature blockListContent[x, y + 1, bz + rely, 2] = blockListContent[x, y, bz + rely, 2];//copy blocks future type } } SetBlock((ushort)(x), (ushort)(y), (ushort)(bz + rely), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, y, bz + rely] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y, z + a - 1]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z + a - 1; //if (player != null) //SendServerMessageToPlayer("green +y +z", player.NetConn); } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 2)// +y -> -x { relx = 0; rely = by - y; relz = 0; if (blockList[bx - rely, y, z] == BlockType.Water || blockList[bx - rely, y, z] == BlockType.Lava) {//water in our way if (blockList[bx - rely, y + 1, z] == BlockType.None) {//push water up one SetBlock((ushort)(bx - rely), (ushort)(y + 1), (ushort)(z), blockList[bx - rely, y, z], PlayerTeam.None); blockListContent[bx - rely, y + 1, z, 1] = blockListContent[bx - rely, y, z, 1];//copy temperature blockListContent[bx - rely, y + 1, z, 2] = blockListContent[bx - rely, y, z, 2];//copy blocks future type } } SetBlock((ushort)(bx - rely), (ushort)(y), (ushort)(z), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[bx - rely, y, z] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x - (a - 1), y, z]; blockListContent[x, y, z, a * 6 + 1] = x - (a - 1); blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z; //if (player != null) //SendServerMessageToPlayer("green +y -x", player.NetConn); } else if (blockListContent[x, y, z, 1] == 0 && blockListContent[x, y, z, 2] == 4)// +y -> -z { relx = 0; rely = by - y; relz = 0; if (blockList[x, y, bz - rely] == BlockType.Water || blockList[x, y, bz - rely] == BlockType.Lava) {//water in our way if (blockList[x, y + 1, bz - rely] == BlockType.None) {//push water up one SetBlock((ushort)(x), (ushort)(y + 1), (ushort)(bz - rely), blockList[x, y, bz - rely], PlayerTeam.None); blockListContent[x, y + 1, bz - rely, 1] = blockListContent[x, y, bz - rely, 1];//copy temperature blockListContent[x, y + 1, bz - rely, 2] = blockListContent[x, y, bz - rely, 2];//copy blocks future type } } SetBlock((ushort)(x), (ushort)(y), (ushort)(bz - rely), (BlockType)(blockListContent[x, y, z, a * 6]), blockCreatorTeam[bx, by, bz]); blockListHP[x, y, bz - rely] = blockListHP[bx, by, bz]; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y, z - (a - 1)]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z - (a - 1); //if (player != null) //SendServerMessageToPlayer("green +y -z", player.NetConn); } //setblockdebris for visible changes SetBlock((ushort)(bx), (ushort)(by), (ushort)(bz), BlockType.None, PlayerTeam.None); } } else { blockListContent[x, y, z, a * 6] = 0;//clear block out blockListContent[x, y, z, a * 6 + 1] = 0; blockListContent[x, y, z, a * 6 + 2] = 0; blockListContent[x, y, z, a * 6 + 3] = 0; repairme = true; //if (player != null) //SendServerMessageToPlayer("Empty requires repair on " + a, player.NetConn); } } if (blockListContent[x, y, z, 1] == 1)//swap between +x -> +y to +x blockListContent[x, y, z, 1] = 0;//blockListContent[x, y, z, 2]; else blockListContent[x, y, z, 1] = 1;//revert to its original position } else { if (player != null) SendServerMessageToPlayer("It's jammed!", player.NetConn); } } } else if (btn == 2) { if (blockListContent[x, y, z, 1] != 1 && blockList[x, y + 1, z] != BlockType.None)//checks hinge vert / if it has a block { //SendServerMessageToPlayer("The hinge must returned to horizontal position.", player.NetConn); blockListContent[x, y, z, 2] += 1; if (blockListContent[x, y, z, 2] > 4) blockListContent[x, y, z, 2] = 0; if (blockListContent[x, y, z, 2] == 1)//1 is not a viable direction to set blockListContent[x, y, z, 2] = 2; if (player != null) { string direction = ""; if (blockListContent[x, y, z, 2] == 0) //+x direction = "North"; else if (blockListContent[x, y, z, 2] == 2) //-x direction = "South"; else if (blockListContent[x, y, z, 2] == 3) //+z direction = "East"; else if (blockListContent[x, y, z, 2] == 4) //-z direction = "West"; SendServerMessageToPlayer("The hinge was rotated to face " + direction + ".", player.NetConn); } for (int a = 2; a < 7; a++) { if (blockListContent[x, y, z, a * 6] > 0) { if (blockListContent[x, y, z, 2] == 0) //+x DebrisEffectAtPoint(x + a, y, z, BlockType.Highlight, 1); else if (blockListContent[x, y, z, 2] == 2) //-x DebrisEffectAtPoint(x - a, y, z, BlockType.Highlight, 1); else if (blockListContent[x, y, z, 2] == 3) //+z DebrisEffectAtPoint(x, y, z + a, BlockType.Highlight, 1); else if (blockListContent[x, y, z, 2] == 4) //-z DebrisEffectAtPoint(x, y, z - a, BlockType.Highlight, 1); } } //rotate without changing anything return true; } blockListContent[x, y, z, 2] += 1; if (blockListContent[x, y, z, 2] > 4) blockListContent[x, y, z, 2] = 0; if (blockListContent[x, y, z, 2] == 1)//1 is not a viable direction to set blockListContent[x, y, z, 2] = 2; //blockListContent[x, y, z, 2] = 3;//2 ;//-x -> + blockListContent[x, y, z, 1] = 1; if (player != null) { string direction = ""; if (blockListContent[x, y, z, 2] == 0) //+x direction = "North"; else if (blockListContent[x, y, z, 2] == 2) //-x direction = "South"; else if (blockListContent[x, y, z, 2] == 3) //+z direction = "East"; else if (blockListContent[x, y, z, 2] == 4) //-z direction = "West"; SendServerMessageToPlayer("The hinge was rotated to face " + direction + ".", player.NetConn); } PlayerTeam team = PlayerTeam.None; if (player != null) team = player.Team; for (int a = 2; a < 7; a++)//7 { if (blockListContent[x, y, z, 2] == 0) { if (!HingeBlockTypes(blockList[x + a - 1, y, z], team)) break; blockListContent[x, y, z, a * 6] = (byte)blockList[x + a - 1, y, z]; blockListContent[x, y, z, a * 6 + 1] = x + a - 1; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z; DebrisEffectAtPoint((float)(blockListContent[x, y, z, a * 6 + 1]), (float)(blockListContent[x, y, z, a * 6 + 2]), (float)(blockListContent[x, y, z, a * 6 + 3]), BlockType.Highlight, 1); //if (player != null) // SendServerMessageToPlayer("lposx:" + (a - 1) + " " + blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]], player.NetConn); } else if (blockListContent[x, y, z, 2] == 2) { if (!HingeBlockTypes(blockList[x - (a - 1), y, z], team)) break; blockListContent[x, y, z, a * 6] = (byte)blockList[x - (a - 1), y, z]; blockListContent[x, y, z, a * 6 + 1] = x - (a - 1); blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z; DebrisEffectAtPoint((float)(blockListContent[x, y, z, a * 6 + 1]), (float)(blockListContent[x, y, z, a * 6 + 2]), (float)(blockListContent[x, y, z, a * 6 + 3]), BlockType.Highlight, 1); //if (player != null) // SendServerMessageToPlayer("lnegx:" + (a - 1) + " " + blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]], player.NetConn); } else if (blockListContent[x, y, z, 2] == 3) { if (!HingeBlockTypes(blockList[x, y, z + a - 1], team)) break; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y, z + a - 1]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z + a - 1; DebrisEffectAtPoint((float)(blockListContent[x, y, z, a * 6 + 1]), (float)(blockListContent[x, y, z, a * 6 + 2]), (float)(blockListContent[x, y, z, a * 6 + 3]), BlockType.Highlight, 1); //if (player != null) // SendServerMessageToPlayer("lposz:" + (a - 1) + " " + blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]], player.NetConn); } else if (blockListContent[x, y, z, 2] == 4) { if (!HingeBlockTypes(blockList[x, y, z - (a - 1)], team)) break; blockListContent[x, y, z, a * 6] = (byte)blockList[x, y, z - (a - 1)]; blockListContent[x, y, z, a * 6 + 1] = x; blockListContent[x, y, z, a * 6 + 2] = y; blockListContent[x, y, z, a * 6 + 3] = z - (a - 1); DebrisEffectAtPoint((float)(blockListContent[x, y, z, a * 6 + 1]), (float)(blockListContent[x, y, z, a * 6 + 2]), (float)(blockListContent[x, y, z, a * 6 + 3]), BlockType.Highlight, 1); //if (player != null) // SendServerMessageToPlayer("lnegz:" + (a - 1) + " " + blockList[blockListContent[x, y, z, a * 6 + 1], blockListContent[x, y, z, a * 6 + 2], blockListContent[x, y, z, a * 6 + 3]], player.NetConn); } } } return true; } if (blockList[x, y, z] != BlockType.None && blockList[x, y, z] != BlockType.Water && blockList[x, y, z] != BlockType.Lava && blockList[x, y, z] != BlockType.Lever && blockList[x, y, z] != BlockType.Plate && player == null) { //activated by a lever? Vector3 originVector = new Vector3(x, y, z); Vector3 destVector = new Vector3(ox, oy, oz); Vector3 finalVector = destVector - originVector; finalVector.Normalize(); blockListContent[x, y, z, 10] = 1; blockListContent[x, y, z, 11] = (int)(finalVector.X * 100); blockListContent[x, y, z, 12] = (int)(finalVector.Y * 100) + 50; blockListContent[x, y, z, 13] = (int)(finalVector.Z * 100); blockListContent[x, y, z, 14] = x * 100; blockListContent[x, y, z, 15] = y * 100; blockListContent[x, y, z, 16] = z * 100; if (blockList[ox, oy, oz] == BlockType.Lever) { for (int a = 1; a < 7; a++) { if (blockListContent[ox, oy, oz, a * 6] > 0) { if (blockListContent[ox, oy, oz, a * 6 + 1] == x && blockListContent[ox, oy, oz, a * 6 + 2] == y && blockListContent[ox, oy, oz, a * 6 + 3] == z) { return false;//this removes link from switch } } } } else if (blockList[ox, oy, oz] == BlockType.Plate) { for (int a = 1; a < 7; a++) { if (blockListContent[ox, oy, oz, a * 6] > 0) { if (blockListContent[ox, oy, oz, a * 6 + 1] == x && blockListContent[ox, oy, oz, a * 6 + 2] == y && blockListContent[ox, oy, oz, a * 6 + 3] == z) { return false;//this removes link from switch } } } } } return false; }
//private bool LocationNearBase(ushort x, ushort y, ushort z) //{ // for (int i=0; i<MAPSIZE; i++) // for (int j=0; j<MAPSIZE; j++) // for (int k = 0; k < MAPSIZE; k++) // if (blockList[i, j, k] == BlockType.HomeBlue || blockList[i, j, k] == BlockType.HomeRed) // { // double dist = Math.Sqrt(Math.Pow(x - i, 2) + Math.Pow(y - j, 2) + Math.Pow(z - k, 2)); // if (dist < 3) // return true; // } // return false; //} public void ThrowRope(Player player, Vector3 playerPosition, Vector3 playerHeading) { bool actionFailed = false; if (player.Alive == false || player.playerToolCooldown > DateTime.Now) { actionFailed = true; } else if (player.Ore > 49) { player.Ore -= 50; SendOreUpdate(player); } else { actionFailed = true; } // If there's no surface within range, bail. Vector3 hitPoint = playerPosition; Vector3 buildPoint = playerPosition; Vector3 exactPoint = playerPosition; ushort x = (ushort)buildPoint.X; ushort y = (ushort)buildPoint.Y; ushort z = (ushort)buildPoint.Z; if (x <= 0 || y <= 0 || z <= 0 || (int)x > MAPSIZE - 1 || (int)y > MAPSIZE - 1 || (int)z > MAPSIZE - 1) actionFailed = true; if (blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Lava || blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Water) actionFailed = true; if (actionFailed) { // Decharge the player's gun. // TriggerConstructionGunAnimation(player, -0.2f); } else { player.playerToolCooldown = DateTime.Now + TimeSpan.FromSeconds((float)(player.GetToolCooldown(PlayerTools.ThrowRope))); // Fire the player's gun. // TriggerConstructionGunAnimation(player, 0.5f); // Build the block. //hitPoint = RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint, 1); exactPoint.Y = exactPoint.Y + (float)0.25;//0.25 = items height uint ii = SetItem(ItemType.Rope, exactPoint, playerHeading, playerHeading * 5, player.Team, 0); itemList[ii].Content[6] = (byte)player.Team;//set teamsafe // player.Ore -= blockCost; // SendResourceUpdate(player); // Play the sound. PlaySound(InfiniminerSound.ConstructionGun, player.Position); } }
public bool Start() { //Setup the variable toggles varBindingsInitialize(); int tmpMaxPlayers = 16; // Read in from the config file. DatafileWriter dataFile = new DatafileWriter("server.config.txt"); if (dataFile.Data.ContainsKey("winningcash")) winningCashAmount = uint.Parse(dataFile.Data["winningcash"], System.Globalization.CultureInfo.InvariantCulture); if (dataFile.Data.ContainsKey("includelava")) includeLava = bool.Parse(dataFile.Data["includelava"]); if (dataFile.Data.ContainsKey("orefactor")) oreFactor = uint.Parse(dataFile.Data["orefactor"], System.Globalization.CultureInfo.InvariantCulture); if (dataFile.Data.ContainsKey("maxplayers")) tmpMaxPlayers = (int)Math.Min(32, uint.Parse(dataFile.Data["maxplayers"], System.Globalization.CultureInfo.InvariantCulture)); if (dataFile.Data.ContainsKey("public")) varSet("public", bool.Parse(dataFile.Data["public"]), true); if (dataFile.Data.ContainsKey("servername")) varSet("name", dataFile.Data["servername"], true); if (dataFile.Data.ContainsKey("sandbox")) varSet("sandbox", bool.Parse(dataFile.Data["sandbox"]), true); if (dataFile.Data.ContainsKey("notnt")) varSet("tnt", !bool.Parse(dataFile.Data["notnt"]), true); if (dataFile.Data.ContainsKey("sphericaltnt")) varSet("stnt", bool.Parse(dataFile.Data["sphericaltnt"]), true); if (dataFile.Data.ContainsKey("insanelava")) varSet("insanelava", bool.Parse(dataFile.Data["insanelava"]), true); if (dataFile.Data.ContainsKey("shockspreadslava")) varSet("sspreads", bool.Parse(dataFile.Data["shockspreadslava"]), true); if (dataFile.Data.ContainsKey("roadabsorbs")) varSet("roadabsorbs", bool.Parse(dataFile.Data["roadabsorbs"]), true); if (dataFile.Data.ContainsKey("minelava")) varSet("minelava", bool.Parse(dataFile.Data["minelava"]), true); if (dataFile.Data.ContainsKey("levelname")) levelToLoad = dataFile.Data["levelname"]; if (dataFile.Data.ContainsKey("greeter")) varSet("greeter", dataFile.Data["greeter"], true); bool autoannounce = true; if (dataFile.Data.ContainsKey("autoannounce")) autoannounce = bool.Parse(dataFile.Data["autoannounce"]); // Load the ban-list. banList = LoadBanList(); // Load the admin-list admins = LoadAdminList(); if (tmpMaxPlayers >= 0) varSet("maxplayers", tmpMaxPlayers, true); // Initialize the server. NetConfiguration netConfig = new NetConfiguration("InfiniminerPlus"); netConfig.MaxConnections = (int)varGetI("maxplayers"); netConfig.Port = 5565; netServer = new InfiniminerNetServer(netConfig); netServer.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true); //netServer.SimulatedMinimumLatency = 0.1f; //netServer.SimulatedLatencyVariance = 0.05f; //netServer.SimulatedLoss = 0.1f; //netServer.SimulatedDuplicates = 0.05f; netServer.Start(); // Initialize variables we'll use. NetBuffer msgBuffer = netServer.CreateBuffer(); NetMessageType msgType; NetConnection msgSender; // Store the last time that we did a flow calculation. DateTime lastFlowCalc = DateTime.Now; //Check if we should autoload a level if (dataFile.Data.ContainsKey("autoload") && bool.Parse(dataFile.Data["autoload"])) { blockList = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE]; blockCreatorTeam = new PlayerTeam[MAPSIZE, MAPSIZE, MAPSIZE]; LoadLevel(levelToLoad); } else { // Calculate initial lava flows. ConsoleWrite("CALCULATING INITIAL LAVA FLOWS"); ConsoleWrite("TOTAL LAVA BLOCKS = " + newMap()); } //Caculate the shape of spherical tnt explosions CalculateExplosionPattern(); // Send the initial server list update. if (autoannounce) PublicServerListUpdate(true); lastMapBackup = DateTime.Now; // Main server loop! ConsoleWrite("SERVER READY"); while (keepRunning) { // Process any messages that are here. while (netServer.ReadMessage(msgBuffer, out msgType, out msgSender)) { try { switch (msgType) { case NetMessageType.ConnectionApproval: { Player newPlayer = new Player(msgSender, null); newPlayer.Handle = Defines.Sanitize(msgBuffer.ReadString()).Trim(); if (newPlayer.Handle.Length == 0) { newPlayer.Handle = "Player"; } string clientVersion = msgBuffer.ReadString(); if (clientVersion != Defines.INFINIMINER_VERSION) { msgSender.Disapprove("VER;" + Defines.INFINIMINER_VERSION); } else if (banList.Contains(newPlayer.IP)) { msgSender.Disapprove("BAN;"); }/* else if (playerList.Count == maxPlayers) { msgSender.Disapprove("FULL;"); }*/ else { if (admins.ContainsKey(newPlayer.IP)) newPlayer.admin = admins[newPlayer.IP]; playerList[msgSender] = newPlayer; //Check if we should compress the map for the client try { bool compression = msgBuffer.ReadBoolean(); if (compression) playerList[msgSender].compression = true; } catch { } toGreet.Add(msgSender); this.netServer.SanityCheck(msgSender); msgSender.Approve(); PublicServerListUpdate(true); } } break; case NetMessageType.StatusChanged: { if (!this.playerList.ContainsKey(msgSender)) { break; } Player player = playerList[msgSender]; if (msgSender.Status == NetConnectionStatus.Connected) { ConsoleWrite("CONNECT: " + playerList[msgSender].Handle + " ( " + playerList[msgSender].IP + " )"); SendCurrentMap(msgSender); SendPlayerJoined(player); PublicServerListUpdate(); } else if (msgSender.Status == NetConnectionStatus.Disconnected) { ConsoleWrite("DISCONNECT: " + playerList[msgSender].Handle); SendPlayerLeft(player, player.Kicked ? "WAS KICKED FROM THE GAME!" : "HAS ABANDONED THEIR DUTIES!"); if (playerList.ContainsKey(msgSender)) playerList.Remove(msgSender); PublicServerListUpdate(); } } break; case NetMessageType.Data: { if (!this.playerList.ContainsKey(msgSender)) { break; } Player player = playerList[msgSender]; //If player isnt arround we dont care anymore - Cbock //If player is suspected of modding ignore updates for this cycle - Cbock if (player.Kicked == true || player.Flagged == true) break; InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte(); switch (dataType) { case InfiniminerMessage.ChatMessage: { // Read the data from the packet. ChatMessageType chatType = (ChatMessageType)msgBuffer.ReadByte(); string chatString = Defines.Sanitize(msgBuffer.ReadString()); if (!ProcessCommand(chatString, GetAdmin(playerList[msgSender].IP), playerList[msgSender])) { ConsoleWrite("CHAT: (" + player.Handle + ") " + chatString); // Append identifier information. if (chatType == ChatMessageType.SayAll) chatString = player.Handle + " (ALL): " + chatString; else chatString = player.Handle + " (TEAM): " + chatString; // Construct the message packet. NetBuffer chatPacket = netServer.CreateBuffer(); chatPacket.Write((byte)InfiniminerMessage.ChatMessage); chatPacket.Write((byte)((player.Team == PlayerTeam.Red) ? ChatMessageType.SayRedTeam : ChatMessageType.SayBlueTeam)); chatPacket.Write(chatString); // Send the packet to people who should recieve it. foreach (Player p in playerList.Values) { if (chatType == ChatMessageType.SayAll || chatType == ChatMessageType.SayBlueTeam && p.Team == PlayerTeam.Blue || chatType == ChatMessageType.SayRedTeam && p.Team == PlayerTeam.Red) if (p.NetConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(chatPacket, p.NetConn, NetChannel.ReliableInOrder3); } } } break; case InfiniminerMessage.UseTool: { Vector3 playerPosition = msgBuffer.ReadVector3(); Vector3 playerHeading = msgBuffer.ReadVector3(); PlayerTools playerTool = (PlayerTools)msgBuffer.ReadByte(); BlockType blockType = (BlockType)msgBuffer.ReadByte(); switch (playerTool) { case PlayerTools.Pickaxe: //Modification to prevent client from ignoring axe cooldown times - Cbock updateTime = DateTime.Now - player.AxeUsed; if (updateTime.TotalSeconds < 0.1f) { player.Flagged = true; } else { player.AxeUsed = DateTime.Now; UsePickaxe(player, playerPosition, playerHeading); } break; case PlayerTools.ConstructionGun: //Modification to prevent client from ignoring gun cooldown times - Cbock updateTime = DateTime.Now - player.GunUsed; if (updateTime.TotalSeconds < 0.35f) { player.Flagged = true; } else { player.GunUsed = DateTime.Now; UseConstructionGun(player, playerPosition, playerHeading, blockType); } //End Mod break; case PlayerTools.DeconstructionGun: //Modification to prevent client from ignoring gun cooldown times - Cbock updateTime = DateTime.Now - player.GunUsed; if (updateTime.TotalSeconds < 0.35f) { player.Flagged = true; } else { player.GunUsed = DateTime.Now; UseDeconstructionGun(player, playerPosition, playerHeading); } //End Mod break; case PlayerTools.ProspectingRadar: UseSignPainter(player, playerPosition, playerHeading); break; case PlayerTools.Detonator: UseDetonator(player); break; } } break; case InfiniminerMessage.SelectClass: { PlayerClass playerClass = (PlayerClass)msgBuffer.ReadByte(); ConsoleWrite("SELECT_CLASS: " + player.Handle + ", " + playerClass.ToString()); switch (playerClass) { case PlayerClass.Engineer: player.OreMax = 350; player.WeightMax = 4; break; case PlayerClass.Miner: player.OreMax = 200; player.WeightMax = 8; break; case PlayerClass.Prospector: player.OreMax = 200; player.WeightMax = 4; break; case PlayerClass.Sapper: player.OreMax = 200; player.WeightMax = 4; break; } SendResourceUpdate(player); } break; case InfiniminerMessage.PlayerSetTeam: { PlayerTeam playerTeam = (PlayerTeam)msgBuffer.ReadByte(); ConsoleWrite("SELECT_TEAM: " + player.Handle + ", " + playerTeam.ToString()); player.Team = playerTeam; SendResourceUpdate(player); SendPlayerSetTeam(player); } break; case InfiniminerMessage.PlayerDead: { ConsoleWrite("PLAYER_DEAD: " + player.Handle); player.Ore = 0; player.Cash = 0; player.Weight = 0; player.Alive = false; SendResourceUpdate(player); SendPlayerDead(player); string deathMessage = msgBuffer.ReadString(); if (deathMessage != "") { msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ChatMessage); msgBuffer.Write((byte)(player.Team == PlayerTeam.Red ? ChatMessageType.SayRedTeam : ChatMessageType.SayBlueTeam)); msgBuffer.Write(player.Handle + " " + deathMessage); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder3); } } break; case InfiniminerMessage.PlayerAlive: { if (toGreet.Contains(msgSender)) { string greeting = varGetS("greeter"); greeting = greeting.Replace("[name]", playerList[msgSender].Handle); if (greeting != "") { NetBuffer greetBuffer = netServer.CreateBuffer(); greetBuffer.Write((byte)InfiniminerMessage.ChatMessage); greetBuffer.Write((byte)ChatMessageType.SayAll); greetBuffer.Write(Defines.Sanitize(greeting)); netServer.SendMessage(greetBuffer, msgSender, NetChannel.ReliableInOrder3); } toGreet.Remove(msgSender); } ConsoleWrite("PLAYER_ALIVE: " + player.Handle); player.Ore = 0; player.Cash = 0; player.Weight = 0; player.Alive = true; SendResourceUpdate(player); SendPlayerAlive(player); } break; case InfiniminerMessage.PlayerUpdate: { player.Position = msgBuffer.ReadVector3(); player.Heading = msgBuffer.ReadVector3(); // Code to pervent speed, no clipping, and flying mods - DCaudill // Find out if the player is in the air Vector3 footPosition = player.Position + new Vector3(0f, -1.5f, 0f); BlockType standingOnBlock = BlockAtPoint(new Vector3(footPosition.X, footPosition.Y, footPosition.Z)); bool inAir = false; if (standingOnBlock == BlockType.None && !CheckOnLadder(player)) inAir = true; // Update the players list of last 10 updates playerList[msgSender].UpdatePositionServer(player.Position, inAir, player.Alive, DateTime.Now); // Check for speed mods and kick if found if (CheckSpeed(player) && player.positionList.Count > 9) { KickPlayer(player.IP); SendServerMessage(player.Handle + " was kicked for speed mods, Sorry"); ConsoleWrite(player.Handle + " was kicked for speed mods, Sorry"); } // Check for flying mods and kick if found if (CheckFlying(player) && player.positionList.Count > 9) { KickPlayer(player.IP); SendServerMessage(player.Handle + " was kicked for flying, Sorry"); ConsoleWrite(player.Handle + " was kicked for flying mods, Sorry"); } // Check for no clipping mods and kick if found if (CheckNoClipping(player) && player.positionList.Count > 9) { KickPlayer(player.IP); SendServerMessage(player.Handle + " was kicked for no clipping, Sorry"); ConsoleWrite(player.Handle + " was kicked for no clipping, Sorry"); } player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); SendPlayerUpdate(player); } break; case InfiniminerMessage.DepositOre: { DepositOre(player); foreach (Player p in playerList.Values) SendResourceUpdate(p); } break; case InfiniminerMessage.WithdrawOre: { WithdrawOre(player); foreach (Player p in playerList.Values) SendResourceUpdate(p); } break; case InfiniminerMessage.PlayerPing: { SendPlayerPing((uint)msgBuffer.ReadInt32()); } break; case InfiniminerMessage.PlaySound: { InfiniminerSound sound = (InfiniminerSound)msgBuffer.ReadByte(); Vector3 position = msgBuffer.ReadVector3(); PlaySound(sound, position); } break; } } break; } } catch { } } // Unflag all clients after data is finished being parsed - Cbock foreach (Player p in playerList.Values) { p.Flagged = false; } //Time to backup map? TimeSpan mapUpdateTimeSpan = DateTime.Now - lastMapBackup; if (mapUpdateTimeSpan.TotalMinutes > 5) { SaveLevel("autoBK.lvl"); } // Time to send a new server update? PublicServerListUpdate(); //It checks for public server / time span //Time to terminate finished map sending threads? TerminateFinishedThreads(); // Check for players who are in the zone to deposit. DepositForPlayers(); // Is it time to do a lava calculation? If so, do it! TimeSpan timeSpan = DateTime.Now - lastFlowCalc; if (timeSpan.TotalMilliseconds > 500) { DoLavaStuff(); lastFlowCalc = DateTime.Now; } // Handle console keypresses. while (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) ConsoleProcessInput(); else if (keyInfo.Key == ConsoleKey.Backspace) { if (consoleInput.Length > 0) consoleInput = consoleInput.Substring(0, consoleInput.Length - 1); ConsoleRedraw(); } else { consoleInput += keyInfo.KeyChar; ConsoleRedraw(); } } // Is the game over? if (winningTeam != PlayerTeam.None && !restartTriggered) { BroadcastGameOver(); restartTriggered = true; restartTime = DateTime.Now.AddSeconds(10); } // Restart the server? if (restartTriggered && DateTime.Now > restartTime) { SaveLevel("autosave_" + (UInt64)DateTime.Now.ToBinary() + ".lvl"); netServer.Shutdown("The server is restarting."); return true; } // Pass control over to waiting threads. Thread.Sleep(1); } MessageAll("Server going down NOW!"); netServer.Shutdown("The server was terminated."); return false; }
public void UseStrongArm(Player player, Vector3 playerPosition, Vector3 playerHeading) { player.QueueAnimationBreak = true; Vector3 headPosition = playerPosition + new Vector3(0f, 0.1f, 0f); // Figure out what we're hitting. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (player.Content[5] == 0) if (!RayCollision(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint, BlockType.Water)) return; if (player.Content[5] > 0) { //Vector3 throwPoint = RayCollisionExact(playerPosition, playerHeading, 10, 100, ref hitPoint, ref buildPoint); //if (throwPoint != playerPosition) //{ //double dist = Distf(playerPosition, throwPoint); //if (dist < 2) // return;//distance of ray should be strength //else { //begin throw buildPoint = headPosition + (playerHeading*2); //RayCollisionExactNone(playerPosition, playerHeading, 2, 10, ref hitPoint, ref buildPoint); // } // } } ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; // Figure out what the result is. bool grabBlock = false; if (player.Content[5] == 0) { uint giveWeight = 0; InfiniminerSound sound = InfiniminerSound.DigDirt; BlockType block = BlockAtPoint(hitPoint); switch (block) { case BlockType.Dirt: case BlockType.Grass: case BlockType.Pump: case BlockType.Barrel: case BlockType.Pipe: case BlockType.Rock: case BlockType.Mud: case BlockType.Sand: case BlockType.DirtSign: case BlockType.StealthBlockB: case BlockType.StealthBlockR: case BlockType.TrapB: case BlockType.TrapR: case BlockType.Ore: case BlockType.Explosive: grabBlock = true; giveWeight = 10; sound = InfiniminerSound.DigMetal; break; case BlockType.SolidBlue: if (player.Team == PlayerTeam.Blue) { grabBlock = true; giveWeight = 10; sound = InfiniminerSound.DigMetal; } break; case BlockType.SolidRed: if (player.Team == PlayerTeam.Red) { grabBlock = true; giveWeight = 10; sound = InfiniminerSound.DigMetal; } break; } if (blockCreatorTeam[x, y, z] == PlayerTeam.Blue && player.Team == PlayerTeam.Red) { return;//dont allow enemy team to manipulate other teams team-blocks } else if (blockCreatorTeam[x, y, z] == PlayerTeam.Red && player.Team == PlayerTeam.Blue) { return; } if (giveWeight > 0) { if (player.Weight + giveWeight <= player.WeightMax) { player.Weight += giveWeight; SendWeightUpdate(player); } else { grabBlock = false; } } if (grabBlock) { player.Content[5] = (byte)block; for (uint cc = 0; cc < 20; cc++)//copy the content values { player.Content[50 + cc] = blockListContent[x, y, z, cc];//50 is past players accessible content, it is for server only } if (block == BlockType.Explosive)//must update player explosive keys { foreach (Player p in playerList.Values) { int cc = p.ExplosiveList.Count; int ca = 0; while(ca < cc) { if (p.ExplosiveList[ca].X == x && p.ExplosiveList[ca].Y == y && p.ExplosiveList[ca].Z == z) { player.Content[50 + 17] = (int)p.ID; p.ExplosiveList.RemoveAt(ca);//experimental break; } ca += 1; } } } SendContentSpecificUpdate(player,5); SetBlock(x, y, z, BlockType.None, PlayerTeam.None); PlaySound(sound, player.Position); } } else {//throw the block BlockType block = (BlockType)(player.Content[5]); if (block != BlockType.None) { ushort bx = (ushort)buildPoint.X; ushort by = (ushort)buildPoint.Y; ushort bz = (ushort)buildPoint.Z; if (blockList[bx, by, bz] == BlockType.None) { SetBlock(bx, by, bz, block, PlayerTeam.None); player.Weight -= 10; player.Content[5] = 0; SendWeightUpdate(player); SendContentSpecificUpdate(player, 5); for (uint cc = 0; cc < 20; cc++)//copy the content values { blockListContent[bx, by, bz, cc] = player.Content[50 + cc]; if (cc == 17 && block == BlockType.Explosive)//explosive list for tnt update { foreach (Player p in playerList.Values) { if (p.ID == (uint)(blockListContent[bx, by, bz, cc])) { //found explosive this belongs to p.ExplosiveList.Add(new Vector3(bx,by,bz)); } } } player.Content[50 + cc] = 0; } blockListContent[bx, by, bz, 10] = 1;//undergoing gravity changes blockListContent[bx, by, bz, 11] = (int)((playerHeading.X*1.2)*100);//1.2 = throw strength blockListContent[bx, by, bz, 12] = (int)((playerHeading.Y*1.2)*100); blockListContent[bx, by, bz, 13] = (int)((playerHeading.Z*1.2)*100); blockListContent[bx, by, bz, 14] = (int)((buildPoint.X) * 100); blockListContent[bx, by, bz, 15] = (int)((buildPoint.Y) * 100); blockListContent[bx, by, bz, 16] = (int)((buildPoint.Z) * 100); blockCreatorTeam[bx, by, bz] = player.Team; PlaySound(InfiniminerSound.GroundHit, player.Position); } } } }
// Checks to see if the player is flying by testing if its alive and stationary // in the air for 6 consecutive updates - DCaudill public bool CheckFlying(Player player) { int counter = 0; for (int i = 0; i < player.positionList.Count; i++) { if (player.positionList[i].inAir && player.positionList[i].deltaY == 0 && player.positionList[i].alive) { counter++; if (counter > 6) return true; } else counter = 0; } return false; }
public bool ProcessCommand(string input, short authority, Player sender) { if (authority == 0) return false; if (sender != null) sender.admin = GetAdmin(sender.IP); string[] args = input.Split(' '.ToString().ToCharArray(), 2); if (args[0].StartsWith("\\") && args[0].Length > 1) args[0] = args[0].Substring(1); switch (args[0].ToLower()) { case "help": { if (sender == null) { ConsoleWrite("SERVER CONSOLE COMMANDS:"); ConsoleWrite(" announce"); ConsoleWrite(" players"); ConsoleWrite(" kick <ip>"); ConsoleWrite(" kickn <name>"); ConsoleWrite(" ban <ip>"); ConsoleWrite(" bann <name>"); ConsoleWrite(" say <message>"); ConsoleWrite(" save <mapfile>"); ConsoleWrite(" load <mapfile>"); ConsoleWrite(" toggle <var>"); ConsoleWrite(" <var> <value>"); ConsoleWrite(" <var>"); ConsoleWrite(" listvars"); ConsoleWrite(" status"); ConsoleWrite(" restart"); ConsoleWrite(" quit"); } else { SendServerMessageToPlayer(sender.Handle + ", the " + args[0].ToLower() + " command is only for use in the server console.", sender.NetConn); } } break; case "players": { if (sender == null) { ConsoleWrite("( " + playerList.Count + " / " + varGetI("maxplayers") + " )"); foreach (Player p in playerList.Values) { string teamIdent = ""; if (p.Team == PlayerTeam.Red) teamIdent = " (R)"; else if (p.Team == PlayerTeam.Blue) teamIdent = " (B)"; if (p.IsAdmin) teamIdent += " (Admin)"; ConsoleWrite(p.Handle + teamIdent); ConsoleWrite(" - " + p.IP); } } else { SendServerMessageToPlayer(sender.Handle + ", the " + args[0].ToLower() + " command is only for use in the server console.", sender.NetConn); } } break; case "admins": { ConsoleWrite("Admin list:"); foreach (string ip in admins.Keys) ConsoleWrite(ip); } break; case "admin": { if (args.Length == 2) { if (sender == null || sender.admin >= 2) AdminPlayer(args[1]); else SendServerMessageToPlayer("You do not have the authority to add admins.", sender.NetConn); } } break; case "adminn": { if (args.Length == 2) { if (sender == null || sender.admin >= 2) AdminPlayer(args[1], true); else SendServerMessageToPlayer("You do not have the authority to add admins.", sender.NetConn); } } break; case "listvars": if (sender == null) varList(true); else { SendServerMessageToPlayer(sender.Handle + ", the " + args[0].ToLower() + " command is only for use in the server console.", sender.NetConn); } break; case "status": if (sender == null) status(); else SendServerMessageToPlayer(sender.Handle + ", the " + args[0].ToLower() + " command is only for use in the server console.", sender.NetConn); break; case "announce": { PublicServerListUpdate(true); } break; case "kick": { if (authority >= 1 && args.Length == 2) { if (sender != null) ConsoleWrite("SERVER: " + sender.Handle + " has kicked " + args[1]); KickPlayer(args[1]); } } break; case "kickn": { if (authority >= 1 && args.Length == 2) { if (sender != null) ConsoleWrite("SERVER: " + sender.Handle + " has kicked " + args[1]); KickPlayer(args[1], true); } } break; case "ban": { if (authority >= 1 && args.Length == 2) { if (sender != null) ConsoleWrite("SERVER: " + sender.Handle + " has banned " + args[1]); BanPlayer(args[1]); KickPlayer(args[1]); } } break; case "bann": { if (authority >= 1 && args.Length == 2) { if (sender != null) ConsoleWrite("SERVER: " + sender.Handle + " has bannec " + args[1]); BanPlayer(args[1], true); KickPlayer(args[1], true); } } break; case "toggle": if (authority >= 1 && args.Length == 2) { int exists = varExists(args[1]); if (exists == 1) { bool val = varGetB(args[1]); varSet(args[1], !val); } else if (exists == 2) ConsoleWrite("Cannot toggle a string value."); else varReportStatus(args[1]); } else ConsoleWrite("Need variable name to toggle!"); break; case "quit": { if (authority >= 2) { if (sender != null) ConsoleWrite(sender.Handle + " is shutting down the server."); keepRunning = false; } } break; case "restart": { if (authority >= 2) { if (sender != null) ConsoleWrite(sender.Handle + " is restarting the server."); disconnectAll(); restartTriggered = true; restartTime = DateTime.Now; } } break; case "say": { if (args.Length == 2) { string message = "SERVER: " + args[1]; SendServerMessage(message); } } break; case "save": { if (args.Length >= 2) { if (sender != null) ConsoleWrite(sender.Handle + " is saving the map."); SaveLevel(args[1]); } } break; case "load": { if (args.Length >= 2) { if (sender != null) ConsoleWrite(sender.Handle + " is loading a map."); LoadLevel(args[1]); /*if (LoadLevel(args[1])) Console.WriteLine("Loaded level " + args[1]); else Console.WriteLine("Level file not found!");*/ } else if (levelToLoad != "") { LoadLevel(levelToLoad); } } break; default: //Check / set var { string name = args[0]; int exists = varExists(name); if (exists > 0) { if (args.Length == 2) { try { if (exists == 1) { bool newVal = false; newVal = bool.Parse(args[1]); varSet(name, newVal); } else if (exists == 2) { varSet(name, args[1]); } else if (exists == 3) { varSet(name, Int32.Parse(args[1])); } } catch { } } else { if (sender == null) varReportStatus(name); else SendServerMessageToPlayer(sender.Handle + ": The " + args[0].ToLower() + " command is only for use in the server console.", sender.NetConn); } } else { char first = args[0].ToCharArray()[0]; if (first == 'y' || first == 'Y') { string message = "SERVER: " + args[0].Substring(1); if (args.Length > 1) message += (message != "SERVER: " ? " " : "") + args[1]; SendServerMessage(message); } else { if (sender == null) ConsoleWrite("Unknown command/var."); return false; } } } break; } return true; }
// Checks to see if the player is on a ladder - DCaudill public bool CheckOnLadder(Player player) { Vector3[] directions = new Vector3[4] { new Vector3(1, 0, 0), new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1)}; Vector3 midBodyPoint; Vector3 lowerBodyPoint; Vector3 uperBodyPoint; for (int j = 0; j < 4; j++) { lowerBodyPoint = player.Position + directions[j] + new Vector3(0, -1.4f, 0); midBodyPoint = player.Position + directions[j] + new Vector3(0, -0.7f, 0); uperBodyPoint = player.Position + directions[j]; BlockType lowerBlock = BlockAtPoint(lowerBodyPoint); BlockType midBlock = BlockAtPoint(midBodyPoint); BlockType upperBlock = BlockAtPoint(uperBodyPoint); if (upperBlock == BlockType.Ladder || lowerBlock == BlockType.Ladder || midBlock == BlockType.Ladder) { return true; } } return false; }
public void SendPlayerJoined(Player player) { NetBuffer msgBuffer; // Let this player know about other players. foreach (Player p in playerList.Values) { msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerJoined); msgBuffer.Write((uint)p.ID); msgBuffer.Write(p.Handle); msgBuffer.Write(p == player); msgBuffer.Write(p.Alive); if (player.NetConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, player.NetConn, NetChannel.ReliableInOrder2); msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerSetTeam); msgBuffer.Write((uint)p.ID); msgBuffer.Write((byte)p.Team); if (player.NetConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, player.NetConn, NetChannel.ReliableInOrder2); } // Let this player know about all placed beacons. foreach (KeyValuePair<Vector3, Beacon> bPair in beaconList) { Vector3 position = bPair.Key; position.Y += 1; // beacon is shown a block below its actually position to make altitude show up right msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.SetBeacon); msgBuffer.Write(position); msgBuffer.Write(bPair.Value.ID); msgBuffer.Write((byte)bPair.Value.Team); if (player.NetConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, player.NetConn, NetChannel.ReliableInOrder2); } // Let other players know about this player. msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerJoined); msgBuffer.Write((uint)player.ID); msgBuffer.Write(player.Handle); msgBuffer.Write(false); msgBuffer.Write(player.Alive); foreach (NetConnection netConn in playerList.Keys) if (netConn != player.NetConn && netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder2); // Send this out just incase someone is joining at the last minute. if (winningTeam != PlayerTeam.None) BroadcastGameOver(); // Send out a chat message. msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ChatMessage); msgBuffer.Write((byte)ChatMessageType.SayAll); msgBuffer.Write(player.Handle + " HAS JOINED THE ADVENTURE!"); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder3); }
//private bool LocationNearBase(ushort x, ushort y, ushort z) //{ // for (int i=0; i<MAPSIZE; i++) // for (int j=0; j<MAPSIZE; j++) // for (int k = 0; k < MAPSIZE; k++) // if (blockList[i, j, k] == BlockType.HomeBlue || blockList[i, j, k] == BlockType.HomeRed) // { // double dist = Math.Sqrt(Math.Pow(x - i, 2) + Math.Pow(y - j, 2) + Math.Pow(z - k, 2)); // if (dist < 3) // return true; // } // return false; //} public void UseConstructionGun(Player player, Vector3 playerPosition, Vector3 playerHeading, BlockType blockType) { bool actionFailed = false; // If there's no surface within range, bail. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 6, 25, ref hitPoint, ref buildPoint)) actionFailed = true; // If the block is too expensive, bail. uint blockCost = BlockInformation.GetCost(blockType); if (varGetB("sandbox") && blockCost <= player.OreMax) // This code gives blocks in sandbox mode correct pricing and denies lavaspam etc. - Cbock blockCost = BlockInformation.GetCostSandbox(blockType); if (blockCost > player.Ore) actionFailed = true; // If there's someone there currently, bail. ushort x = (ushort)buildPoint.X; ushort y = (ushort)buildPoint.Y; ushort z = (ushort)buildPoint.Z; foreach (Player p in playerList.Values) { if ((int)p.Position.X == x && (int)p.Position.Z == z && ((int)p.Position.Y == y || (int)p.Position.Y - 1 == y)) actionFailed = true; } // If it's out of bounds, bail. if (x <= 0 || y <= 0 || z <= 0 || (int)x >= MAPSIZE - 1 || (int)y >= MAPSIZE - 1 || (int)z >= MAPSIZE - 1) actionFailed = true; // If it's near a base, bail. //if (LocationNearBase(x, y, z)) // actionFailed = true; // If it's lava, don't let them build off of lava. if (blockList[(ushort)hitPoint.X, (ushort)hitPoint.Y, (ushort)hitPoint.Z] == BlockType.Lava) actionFailed = true; if (actionFailed) { // Decharge the player's gun. TriggerConstructionGunAnimation(player, -0.2f); } else { // Fire the player's gun. TriggerConstructionGunAnimation(player, 0.5f); // Build the block. SetBlock(x, y, z, blockType, player.Team); player.Ore -= blockCost; SendResourceUpdate(player); // Play the sound. PlaySound(InfiniminerSound.ConstructionGun, player.Position); // If it's an explosive block, add it to our list. if (blockType == BlockType.Explosive) player.ExplosiveList.Add(buildPoint); } }
public void SendPlayerLeft(Player player, string reason) { NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerLeft); msgBuffer.Write((uint)player.ID); foreach (NetConnection netConn in playerList.Keys) if (netConn != player.NetConn && netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder2); // Send out a chat message. msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ChatMessage); msgBuffer.Write((byte)ChatMessageType.SayAll); msgBuffer.Write(player.Handle + " " + reason); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder3); }
public void UseDetonator(Player player) { while (player.ExplosiveList.Count > 0) { Vector3 blockPos = player.ExplosiveList[0]; ushort x = (ushort)blockPos.X; ushort y = (ushort)blockPos.Y; ushort z = (ushort)blockPos.Z; if (blockList[x, y, z] != BlockType.Explosive) player.ExplosiveList.RemoveAt(0); else if (!varGetB("tnt")) { player.ExplosiveList.RemoveAt(0); ExplosionEffectAtPoint(x, y, z); // Remove the block that is detonating. SetBlock(x, y, z, BlockType.None, PlayerTeam.None); } else DetonateAtPoint(x, y, z); } }
public void SendPlayerSetTeam(Player player) { NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerSetTeam); msgBuffer.Write((uint)player.ID); msgBuffer.Write((byte)player.Team); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableInOrder2); }
public void UseSignPainter(Player player, Vector3 playerPosition, Vector3 playerHeading) { // If there's no surface within range, bail. Vector3 hitPoint = Vector3.Zero; Vector3 buildPoint = Vector3.Zero; if (!RayCollision(playerPosition, playerHeading, 4, 25, ref hitPoint, ref buildPoint)) return; ushort x = (ushort)hitPoint.X; ushort y = (ushort)hitPoint.Y; ushort z = (ushort)hitPoint.Z; if (blockList[x, y, z] == BlockType.Dirt) { SetBlock(x, y, z, BlockType.DirtSign, PlayerTeam.None); PlaySound(InfiniminerSound.ConstructionGun, player.Position); } else if (blockList[x, y, z] == BlockType.DirtSign) { SetBlock(x, y, z, BlockType.Dirt, PlayerTeam.None); PlaySound(InfiniminerSound.ConstructionGun, player.Position); } }
public void SendPlayerUpdate(Player player) { NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerUpdate); msgBuffer.Write((uint)player.ID); msgBuffer.Write(player.Position); msgBuffer.Write(player.Heading); msgBuffer.Write((byte)player.Tool); if (player.QueueAnimationBreak) { player.QueueAnimationBreak = false; msgBuffer.Write(false); } else msgBuffer.Write(player.UsingTool); msgBuffer.Write((ushort)player.Score / 100); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.UnreliableInOrder1); }
public void WithdrawOre(Player player) { if (player.Team == PlayerTeam.Red) { uint withdrawAmount = Math.Min(player.OreMax - player.Ore, Math.Min(50, teamOreRed)); player.Ore += withdrawAmount; teamOreRed -= withdrawAmount; } else { uint withdrawAmount = Math.Min(player.OreMax - player.Ore, Math.Min(50, teamOreBlue)); player.Ore += withdrawAmount; teamOreBlue -= withdrawAmount; } }
// Lets a player know about their resources. public void SendResourceUpdate(Player player) { if (player.NetConn.Status != NetConnectionStatus.Connected) return; // ore, cash, weight, max ore, max weight, team ore, red cash, blue cash, all uint NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.ResourceUpdate); msgBuffer.Write((uint)player.Ore); msgBuffer.Write((uint)player.Cash); msgBuffer.Write((uint)player.Weight); msgBuffer.Write((uint)player.OreMax); msgBuffer.Write((uint)player.WeightMax); msgBuffer.Write((uint)(player.Team == PlayerTeam.Red ? teamOreRed : teamOreBlue)); msgBuffer.Write((uint)teamCashRed); msgBuffer.Write((uint)teamCashBlue); netServer.SendMessage(msgBuffer, player.NetConn, NetChannel.ReliableInOrder1); }
public void DepositOre(Player player) { uint depositAmount = Math.Min(50, player.Ore); player.Ore -= depositAmount; if (player.Team == PlayerTeam.Red) teamOreRed = Math.Min(teamOreRed + depositAmount, 9999); else teamOreBlue = Math.Min(teamOreBlue + depositAmount, 9999); }
public void SetRemote(Player player, uint btn, uint x, uint y, uint z) { if(x > 0 && x < MAPSIZE - 1 && y > 0 && y < MAPSIZE - 1 && z > 0 && z < MAPSIZE - 1) { player.Content[5] = (int)btn; player.Content[6] = (int)x; player.Content[7] = (int)y; player.Content[8] = (int)z; SendServerMessageToPlayer("linked remote to action " + btn + " on " + blockList[x, y, z] + ".", player.NetConn); } }