コード例 #1
0
ファイル: OpenHandItem.cs プロジェクト: Morphan1/Voxalia
 public void Grab(PlayerEntity player, PhysicsEntity pe, Location hit)
 {
     AltClick(player, null);
     JointBallSocket jbs = new JointBallSocket(player.CursorMarker, pe, hit);
     player.TheRegion.AddJoint(jbs);
     player.GrabJoint = jbs;
 }
コード例 #2
0
 public void Execute(PlayerEntity entity, List<string> arguments, string commandname)
 {
     PlayerCommandEntry entry = new PlayerCommandEntry();
     entry.Player = entity;
     entry.InputArguments = arguments;
     entry.Command = GetCommand(commandname);
     if (entry.Command == null || !entry.Command.Silent)
     {
         StringBuilder args = new StringBuilder();
         for (int i = 0; i < arguments.Count; i++)
         {
             args.Append(" \"").Append(arguments[i]).Append("\"");
         }
         SysConsole.Output(OutputType.INFO, "Client " + entity + " executing command '" + commandname + "' with arguments:" + args.ToString());
     }
     // TODO: Permission
     // TODO: Fire command event
     if (entry.Command == null)
     {
         entry.Player.SendMessage(TextChannel.COMMAND_RESPONSE, "Unknown command."); // TODO: Noise mode // TODO: Language
     }
     else
     {
         entry.Command.Execute(entry);
     }
 }
コード例 #3
0
ファイル: WingsItem.cs プロジェクト: Morphan1/Voxalia
 public void CloseWings(PlayerEntity player)
 {
     if (player.Wings != null)
     {
         player.TheRegion.DespawnEntity(player.Wings);
         player.Wings = null;
     }
 }
コード例 #4
0
 public SetStatusPacketOut(PlayerEntity player, ClientStatus opt, byte status)
 {
     UsageType = NetUsageType.PLAYERS;
     ID = ServerToClientPacket.SET_STATUS;
     Data = new byte[8 + 1 + 1];
     Utilities.LongToBytes(player.EID).CopyTo(Data, 0);
     Data[8] = (byte)opt;
     Data[8 + 1] = status;
 }
コード例 #5
0
 public FlashLightPacketOut(PlayerEntity player, bool enabled, double distance, Location color)
 {
     UsageType = NetUsageType.PLAYERS;
     ID = ServerToClientPacket.FLASHLIGHT;
     Data = new byte[8 + 1 + 4 + 24];
     Utilities.LongToBytes(player.EID).CopyTo(Data, 0);
     Data[8] = (byte)(enabled ? 1 : 0);
     Utilities.FloatToBytes((float)distance).CopyTo(Data, 8 + 1);
     color.ToDoubleBytes().CopyTo(Data, 8 + 1 + 4);
 }
コード例 #6
0
ファイル: HookItem.cs プロジェクト: Morphan1/Voxalia
 public void ApplyHook(PlayerEntity player, ItemStack item, Location Position, BEPUphysics.Entities.Entity HitEnt)
 {
     RemoveHook(player);
     PhysicsEntity pe;
     double len = (double)(Position - player.GetCenter()).Length();
     Location step = (player.GetCenter() - Position) / len;
     Location forw = Utilities.VectorToAngles(step);
     BEPUutilities.Quaternion quat = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (double)(forw.Pitch * Utilities.PI180)) *
         Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (double)(forw.Yaw * Utilities.PI180));
     if (HitEnt == null)
     {
         ModelEntity mod = new ModelEntity("cube", player.TheRegion);
         mod.Mass = 0;
         mod.CanSave = false;
         mod.scale = new Location(0.023, 0.05, 0.05);
         mod.mode = ModelCollisionMode.AABB;
         mod.SetPosition(Position);
         mod.SetOrientation(quat);
         player.TheRegion.SpawnEntity(mod);
         pe = mod;
         player.Hooks.Add(new HookInfo() { Joint = null, Hit = pe, IsBar = true });
     }
     else
     {
         pe = (PhysicsEntity)HitEnt.Tag;
     }
     JointDistance jd;
     //jd = new JointDistance(player, pe, 0.01f, len + 0.01f, player.GetCenter(), Position);
     //player.TheRegion.AddJoint(jd);
     //player.Hooks.Add(new HookInfo() { Joint = jd, Hit = pe, IsBar = false });
     PhysicsEntity cent = pe;
     for (double f = 0; f < len - 1f; f += 0.5f)
     {
         Location cpos = Position + step * f;
         ModelEntity ce = new ModelEntity("cube", player.TheRegion);
         ce.Mass = 15;
         ce.CanSave = false;
         ce.scale = new Location(0.023, 0.05, 0.05);
         ce.mode = ModelCollisionMode.AABB;
         ce.SetPosition(cpos + step * 0.5);
         ce.SetOrientation(quat);
         player.TheRegion.SpawnEntity(ce);
         jd = new JointDistance(ce, cent, 0.01f, 0.5f, ce.GetPosition(), (ReferenceEquals(cent, pe) ? Position: cent.GetPosition()));
         CollisionRules.AddRule(player.Body, ce.Body, CollisionRule.NoBroadPhase);
         player.TheRegion.AddJoint(jd);
         player.Hooks.Add(new HookInfo() { Joint = jd, Hit = ce, IsBar = true });
         cent = ce;
     }
     jd = new JointDistance(cent, player, 0.01f, 0.5f, cent.GetPosition(), player.GetCenter());
     player.TheRegion.AddJoint(jd);
     player.Hooks.Add(new HookInfo() { Joint = jd, Hit = player, IsBar = false });
 }
コード例 #7
0
ファイル: WingsItem.cs プロジェクト: Morphan1/Voxalia
 public void OpenWings(PlayerEntity player)
 {
     PlaneEntity plane = new PlaneEntity("planeifound", player.TheRegion); // TODO: Player-wings model!
     plane.SetMass(100);
     plane.SetPosition(player.GetPosition());
     player.TheRegion.SpawnEntity(plane);
     plane.SetOrientation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, -90.0 * Utilities.PI180));
     plane.DriverSeat.Accept(player);
     player.Wings = plane;
     // JUST IN CASE: Enforce the correct default orientation!
     // TODO: Make this not needed!
     player.TheRegion.TheWorld.Schedule.ScheduleSyncTask(() =>
     {
         plane.SetOrientation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, -90.0 * Utilities.PI180));
     }, 0.05);
 }
コード例 #8
0
ファイル: HookItem.cs プロジェクト: Morphan1/Voxalia
 public static void RemoveHook(PlayerEntity player)
 {
     if (player.Hooks.Count > 0)
     {
         for (int i = 0; i < player.Hooks.Count; i++)
         {
             if (player.Hooks[i].Joint != null)
             {
                 player.TheRegion.DestroyJoint(player.Hooks[i].Joint);
             }
         }
         for (int i = 0; i < player.Hooks.Count; i++)
         {
             if (player.Hooks[i].IsBar)
             {
                 player.Hooks[i].Hit.RemoveMe();
             }
         }
         player.Hooks.Clear();
     }
 }
コード例 #9
0
ファイル: FlashLightItem.cs プロジェクト: Morphan1/Voxalia
 public void On(PlayerEntity player)
 {
     player.TheRegion.SendToAll(new FlashLightPacketOut(player, true, Distance, Color));
     player.FlashLightOn = true;
 }
コード例 #10
0
ファイル: FlashLightItem.cs プロジェクト: Morphan1/Voxalia
 public static void Off(PlayerEntity player)
 {
     player.TheRegion.SendToAll(new FlashLightPacketOut(player, false, 0, Location.Zero));
     player.FlashLightOn = false;
 }
コード例 #11
0
ファイル: HookItem.cs プロジェクト: Morphan1/Voxalia
 public void Shrink(PlayerEntity player)
 {
     for (int i = 0; i < player.Hooks.Count; i++)
     {
         if (player.Hooks[i].Joint != null)
         {
             if (player.Hooks[i].Joint.Max > 0.3f)
             {
                 player.Hooks[i].Joint.Max *= 0.9f;
                 // TODO: less lazy networking of this
                 player.TheRegion.DestroyJoint(player.Hooks[i].Joint);
                 player.TheRegion.AddJoint(player.Hooks[i].Joint);
             }
         }
     }
 }
コード例 #12
0
ファイル: PlayerTag.cs プロジェクト: Morphan1/Voxalia
 public PlayerTag(PlayerEntity p)
 {
     Internal = p;
 }
コード例 #13
0
ファイル: HatCannonItem.cs プロジェクト: Morphan1/Voxalia
 public override ArrowEntity SpawnArrow(PlayerEntity player, ItemStack item, double timeStretched)
 {
     ArrowEntity arrow = base.SpawnArrow(player, item, timeStretched);
     arrow.HasHat = true;
     return arrow;
 }
コード例 #14
0
 // TODO: Should non-players be allowed here?
 public void Copy(PlayerEntity player, ItemStack item)
 {
     try
     {
         Structure structure = new Structure(player.TheRegion, player.Selection.Min, player.Selection.Max, player.GetPosition().GetBlockLocation());
         int c = 0;
         while (player.TheServer.Files.Exists("structures/" + item.SecondaryName + c + ".str"))
         {
             c++;
         }
         player.TheServer.Files.WriteBytes("structures/" + item.SecondaryName + c + ".str", structure.ToBytes());
         player.SendMessage(TextChannel.DEBUG_INFO, "^2Saved structure as " + item.SecondaryName + c);
         // TODO: Click sound!
         player.LastBlockBreak = player.TheRegion.GlobalTickTime;
     }
     catch (Exception ex)
     {
         Utilities.CheckException(ex);
         player.SendMessage(TextChannel.DEBUG_INFO, "^1Failed to create structure: " + ex.Message);
     }
 }
コード例 #15
0
ファイル: PlayerInventory.cs プロジェクト: Morphan1/Voxalia
 public PlayerInventory(PlayerEntity player)
     : base(player.TheRegion, player)
 {
 }
コード例 #16
0
 public override ArrowEntity SpawnArrow(PlayerEntity player, ItemStack item, double timeStretched)
 {
     ArrowEntity ae = base.SpawnArrow(player, item, timeStretched);
     ae.Collide += (o, o2) => { ae.TheRegion.Explode(ae.GetPosition(), 5); };
     return ae;
 }
コード例 #17
0
ファイル: Connection.cs プロジェクト: Morphan1/Voxalia
 public void Tick(double delta)
 {
     try
     {
         Time += delta;
         if (!GotBase && Time >= MaxTime)
         {
             throw new Exception("Connection timed out!");
         }
         int avail = PrimarySocket.Available;
         if (avail <= 0)
         {
             return;
         }
         if (avail + recdsofar > MAX)
         {
             avail = MAX - recdsofar;
             if (avail == 0)
             {
                 throw new Exception("Received overly massive packet?!");
             }
         }
         PrimarySocket.Receive(recd, recdsofar, avail, SocketFlags.None);
         recdsofar += avail;
         if (recdsofar < 5)
         {
             return;
         }
         if (trying)
         {
             return;
         }
         if (GotBase)
         {
             while (true)
             {
                 byte[] len_bytes = new byte[4];
                 Array.Copy(recd, len_bytes, 4);
                 int len = Utilities.BytesToInt(len_bytes);
                 if (len + 5 > MAX)
                 {
                     throw new Exception("Unreasonably huge packet!");
                 }
                 if (recdsofar < 5 + len)
                 {
                     return;
                 }
                 ClientToServerPacket packetID = (ClientToServerPacket)recd[4];
                 byte[] data = new byte[len];
                 Array.Copy(recd, 5, data, 0, len);
                 byte[] rem_data = new byte[recdsofar - (len + 5)];
                 if (rem_data.Length > 0)
                 {
                     Array.Copy(recd, len + 5, rem_data, 0, rem_data.Length);
                     Array.Copy(rem_data, recd, rem_data.Length);
                 }
                 recdsofar -= len + 5;
                 AbstractPacketIn packet;
                 switch (packetID) // TODO: Packet registry?
                 {
                     case ClientToServerPacket.PING:
                         packet = new PingPacketIn();
                         break;
                     case ClientToServerPacket.KEYS:
                         packet = new KeysPacketIn();
                         break;
                     case ClientToServerPacket.COMMAND:
                         packet = new CommandPacketIn();
                         break;
                     case ClientToServerPacket.HOLD_ITEM:
                         packet = new HoldItemPacketIn();
                         break;
                     case ClientToServerPacket.DISCONNECT:
                         packet = new DisconnectPacketIn();
                         break;
                     case ClientToServerPacket.SET_STATUS:
                         packet = new SetStatusPacketIn();
                         break;
                     case ClientToServerPacket.PLEASE_REDEFINE:
                         packet = new PleaseRedefinePacketIn();
                         break;
                     default:
                         throw new Exception("Invalid packet ID: " + packetID);
                 }
                 packet.Chunk = PE.ChunkNetwork == this;
                 packet.Player = PE;
                 PE.TheRegion.TheWorld.Schedule.ScheduleSyncTask(() =>
                 {
                     if (!packet.ParseBytesAndExecute(data))
                     {
                         throw new Exception("Imperfect packet data for " + packetID);
                     }
                 });
             }
         }
         else
         {
             if (recd[0] == 'G' && recd[1] == 'E' && recd[2] == 'T' && recd[3] == ' ' && recd[4] == '/')
             {
                 // HTTP GET
                 if (recd[recdsofar - 1] == '\n' && (recd[recdsofar - 2] == '\n' || recd[recdsofar - 3] == '\n'))
                 {
                     WebPage wp = new WebPage(TheServer, this);
                     wp.Init(FileHandler.encoding.GetString(recd, 0, recdsofar));
                     PrimarySocket.Send(wp.GetFullData());
                     PrimarySocket.Close(5);
                     Alive = false;
                 }
             }
             else if (recd[0] == 'P' && recd[1] == 'O' && recd[2] == 'S' && recd[3] == 'T' && recd[4] == ' ')
             {
                 // HTTP POST
                 throw new NotImplementedException("HTTP POST not yet implemented");
             }
             else if (recd[0] == 'H' && recd[1] == 'E' && recd[2] == 'A' && recd[3] == 'D' && recd[4] == ' ')
             {
                 // HTTP HEAD
                 if (recd[recdsofar - 1] == '\n' && (recd[recdsofar - 2] == '\n' || recd[recdsofar - 3] == '\n'))
                 {
                     WebPage wp = new WebPage(TheServer, this);
                     wp.Init(FileHandler.encoding.GetString(recd, 0, recdsofar));
                     PrimarySocket.Send(FileHandler.encoding.GetBytes(wp.GetHeaders()));
                     PrimarySocket.Close(5);
                     Alive = false;
                 }
             }
             else if (recd[0] == 'V' && recd[1] == 'O' && recd[2] == 'X' && recd[3] == 'p' && recd[4] == '_')
             {
                 // VOXALIA ping
                 if (recd[recdsofar - 1] == '\n')
                 {
                     PrimarySocket.Send(FileHandler.encoding.GetBytes("SUCCESS\rVoxalia Server Online\n"));
                     PrimarySocket.Close(5);
                     Alive = false;
                 }
             }
             else if (recd[0] == 'V' && recd[1] == 'O' && recd[2] == 'X' && recd[3] == '_' && recd[4] == '_')
             {
                 // VOXALIA connect
                 if (recd[recdsofar - 1] == '\n')
                 {
                     string data = FileHandler.encoding.GetString(recd, 6, recdsofar - 6);
                     string[] datums = data.SplitFast('\r');
                     if (datums.Length != 4)
                     {
                         throw new Exception("Invalid VOX__ connection details!");
                     }
                     string name = datums[0];
                     string key = datums[1];
                     string host = datums[2];
                     string port = datums[3];
                     if (!Utilities.ValidateUsername(name))
                     {
                         throw new Exception("Invalid connection - unreasonable username!");
                     }
                     trying = true;
                     TheServer.Schedule.StartASyncTask(() =>
                     {
                         try
                         {
                             CheckWebSession(name, key);
                             TheServer.LoadedWorlds[0].Schedule.ScheduleSyncTask(() =>
                             {
                                 // TODO: Additional details?
                                 // TODO: Choose a world smarter.
                                 PlayerEntity player = new PlayerEntity(TheServer.LoadedWorlds[0].MainRegion, this, name);
                                 player.SessionKey = key;
                                 PE = player;
                                 player.Host = host;
                                 player.Port = port;
                                 player.IP = PrimarySocket.RemoteEndPoint.ToString();
                                 TheServer.Schedule.ScheduleSyncTask(() =>
                                 {
                                     TheServer.PlayersWaiting.Add(player);
                                     PrimarySocket.Send(FileHandler.encoding.GetBytes("ACCEPT\n"));
                                 });
                                 GotBase = true;
                                 recdsofar = 0;
                                 trying = false;
                             });
                         }
                         catch (Exception ex)
                         {
                             TheServer.Schedule.ScheduleSyncTask(() =>
                             {
                                 if (!Alive)
                                 {
                                     return;
                                 }
                                 PrimarySocket.Close();
                                 Utilities.CheckException(ex);
                                 SysConsole.Output(OutputType.WARNING, "Forcibly disconnected client: " + ex.GetType().Name + ": " + ex.Message);
                                 if (TheServer.CVars.s_debug.ValueB)
                                 {
                                     SysConsole.Output(ex);
                                 }
                                 Alive = false;
                             });
                         }
                     });
                 }
             }
             else if (recd[0] == 'V' && recd[1] == 'O' && recd[2] == 'X' && recd[3] == 'c' && recd[4] == '_')
             {
                 // VOXALIA chunk connect
                 if (recd[recdsofar - 1] == '\n')
                 {
                     string data = FileHandler.encoding.GetString(recd, 6, recdsofar - 6);
                     string[] datums = data.SplitFast('\r');
                     if (datums.Length != 4)
                     {
                         throw new Exception("Invalid VOXc_ connection details!");
                     }
                     string name = datums[0];
                     string key = datums[1];
                     string host = datums[2];
                     string port = datums[3];
                     if (!Utilities.ValidateUsername(name))
                     {
                         throw new Exception("Invalid connection - unreasonable username!");
                     }
                     TheServer.Schedule.ScheduleSyncTask(() =>
                     {
                         PlayerEntity player = null;
                         for (int i = 0; i < TheServer.PlayersWaiting.Count; i++)
                         {
                             if (TheServer.PlayersWaiting[i].Name == name && TheServer.PlayersWaiting[i].Host == host &&
                                 TheServer.PlayersWaiting[i].Port == port && TheServer.PlayersWaiting[i].SessionKey == key)
                             {
                                 player = TheServer.PlayersWaiting[i];
                                 TheServer.PlayersWaiting.RemoveAt(i);
                                 break;
                             }
                         }
                         if (player == null)
                         {
                             throw new Exception("Can't find player for VOXc_!");
                         }
                         PE = player;
                         player.ChunkNetwork = this;
                         PrimarySocket.Send(FileHandler.encoding.GetBytes("ACCEPT\n"));
                         // TODO: What if the world disappears during connect sequence?
                         player.LastPingByte = 0;
                         player.LastCPingByte = 0;
                         PrimarySocket.SendBufferSize *= 10;
                         SendPacket(new PingPacketOut(0));
                         player.Network.SendPacket(new PingPacketOut(0));
                         player.SendStatus();
                         GotBase = true;
                         recdsofar = 0;
                         player.TheRegion.TheWorld.Schedule.ScheduleSyncTask(() =>
                         {
                             player.InitPlayer();
                             player.TheRegion.SpawnEntity(player);
                         });
                     });
                 }
             }
             else
             {
                 throw new Exception("Unknown initial byte set!");
             }
         }
     }
     catch (Exception ex)
     {
         PrimarySocket.Close();
         try
         {
             if (PE != null)
             {
                 PE.Kick("Internal exception.");
             }
         }
         finally
         {
             Utilities.CheckException(ex);
             SysConsole.Output(OutputType.WARNING, "Forcibly disconnected client: " + ex.GetType().Name + ": " + ex.Message);
             if (TheServer.CVars.s_debug.ValueB)
             {
                 SysConsole.Output(ex);
             }
             Alive = false;
         }
     }
 }
コード例 #18
0
ファイル: BowItem.cs プロジェクト: Morphan1/Voxalia
 public virtual ArrowEntity SpawnArrow(PlayerEntity player, ItemStack item, double timeStretched)
 {
     ArrowEntity ae = new ArrowEntity(player.TheRegion);
     ae.SetPosition(player.GetEyePosition());
     ae.NoCollide.Add(player.EID);
     Location forward = player.ForwardVector();
     ae.SetVelocity(forward * timeStretched * 20 * FireStrength);
     Matrix lookatlh = Utilities.LookAtLH(Location.Zero, forward, Location.UnitZ);
     lookatlh.Transpose();
     ae.Angles = Quaternion.CreateFromRotationMatrix(lookatlh);
     ae.Angles *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, 90f * (double)Utilities.PI180);
     player.TheRegion.SpawnEntity(ae);
     return ae;
 }