* Adding new websocket transport soon that doesn't depend on library
* Code for old transport can now be found here https://github.com/MirrorNetworking/NinjaWebSocketsTransport
* We shouldn't need to replace with empty files from store as having this in project should not break things
* perf: NetworkIdentity DirtyComponentsMask code removed entirely. OnSerialize now includes the component index as byte before serializing each component. Faster because we avoid GetDirtyComponentsMask() and GetSyncModeObserversMask() calculations. Increases allowed NetworkBehaviour components from 64 to 255. Bandwidth is now smaller if <8 components, and larger if >8 components. Code is significantly more simple.
* Update Assets/Mirror/Runtime/NetworkIdentity.cs
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
* Users must initialize syncobjects (#391)
Previously we initialized syncobjects, so this is valid:
```cs
public class Pepe : NetworkBehavior {
public SyncList<int> mylist;
}
```
With this change, users must initialize their own fields:
```cs
public class Pepe : NetworkBehavior {
public SyncList<int> mylist = new SyncList<int>();
}
```
BREAKING CHANGE: You must initialize all your SyncLists
* Add null check
* This is no longer a weaver error
* Update Assets/Mirror/Runtime/NetworkBehaviour.cs
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
* Remove unnecesary using
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
* Server Teleport Enchancement for NetworkTransform
Related to this issue: https://github.com/vis2k/Mirror/issues/2200
* Improvements on NetworkTransformBase
We disable clientAuthority until teleportation is finished and acknowledged. We set the goal and start data points to null before teleportation.
We set the clientAuthority back to it's initial value registered on server, both on the server and client side; it seems like we don't need to change it to anything on Client side because to my understanding clientAuthortiy is not affecting anything on client side. I may be wrong but still it is a great practice to set it back to it's initial value just in case...
* Added teleportation with rotation
I forgot to add a rotation functionality on my previous commit. It wouldn't be a teleportation without also changing the rotation. If provided a rotation input it will teleport with a rotation, if not it will simply protect the original rotation before the teleportation.
* Removed my debug statement
I forgot to remove the debug log statement lol silly me
* fixing up code
* resetting goal and last pos on server and client
* renaming variables
* making sure TeleportFinished can't request authority at any time
* moving teleport block
* removing duplicate lines
Co-authored-by: Emre Bugday <47198270+EmreB99@users.noreply.github.com>
* breaking: no need to override Serialize/Deserialize in messages
Messages no longer serilize themselves. This has been decoupled. Serializing a message is now done
via readers and writers, which can be either generated or user provided.
This lifts some restrictions,
* you no longer need to have a default constructor in messages
* Messages types can be recursive
* struct Messages don't need to provide an empty Serialize and Deserialize method
Before:
```cs
public struct ReadyMessage : IMessageBase
{
public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
```
After:
```cs
public struct ReadyMessage : IMessageBase
{
}
```
BREAKING CHANGE: Messages must be public
BREAKING CHANGE: Use custom reader and writer instead of Serialize/Deserialize methods
* Remove unused method
* remove unused methods
* remove unused methods
* make all messages struct
* Fix test code generator
* Get rid of MessageBase
* Rename IMessageBase -> NetworkMessage
* add MessageBase as obsolete
* Use a default request
* Empty file to make asset store happy
* Apply suggestions from code review
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
* Fixed OnStopClient not being called on Client Side
* Moved identity.OnStopClient() two scopes above
Co-authored-by: Emre Bugday <47198270+EmreB99@users.noreply.github.com>
* feat: Use SyncLists directly
Previously, you had to write an intermediary class to use synclists, syncsets and syncdictionaries.
The weaver would populate that intermediary class with a serialization and deserialization method
This PR gets rid of 90% of the weaver code for synclists.
There is no need to generate these methods anymore.
Instead the lists use `writer.Write<T>` and `read.read<T>` to serialize their Data.
Since there is no code generate in synclists, you can now use the synclists directly instead
of subclassing them.
BEFORE:
```cs
public class MyComponent : NetworkBehaviour {
// nonsense class to make the weaver happy
class SyncListData : Synclist<Data> {}
SyncListData mySyncList;
}
```
AFTER:
```cs
public class MyComponent : NetworkBehaviour {
Synclist<Data> mySyncList;
}
```
* linting
* feat: Use SyncLists directly (no overrides)
Previously, you had to write an intermediary class to use synclists and syncdictionaries.
The weaver would populate that intermediary class with a serialization and deserialization method
This PR gets rid of 90% of the weaver code for synclists.
There is no need to generate these methods anymore.
Instead the lists use `writer.Write<T>` and `read.read<T>` to serialize their Data.
Since there is no code generate in synclists, you can now use the synclists directly instead
of subclassing them.
Same as #2305 ,but it removes the deprecated Serialize and Deserialize methods from syncobjects,
This way you get a nice compiler error for the code that no longer works, instead of a warning you might accidentally ignore.
BEFORE:
```cs
public class MyComponent : NetworkBehaviour {
// nonsense class to make the weaver happy
class SyncListData : Synclist<Data> {}
SyncListData mySyncList;
}
```
AFTER:
```cs
public class MyComponent : NetworkBehaviour {
Synclist<Data> mySyncList;
}
```
BREAKING CHANGE: Serialize and Deserialize methods in synclists don't do anything anymore
* Remove old comment
* Fix compilatio error
Currently in mirror, there is no way for Mirror itself to invoke
readers and writers for types it does not know about.
This causes us to have to generate code for lists, dictionaries and messages.
This PR makes it so that if there is a reader and writer anywhere in the
code for type X, then the writer can be invoked like this:
```cs
X x = ...;
writer.Write<X>(x);
```
and the reader can be invoked like this:
```cs
X x = reader.Read<X>();
```
* fix: generic arguments lookup
The weaver was not able to figure out the synclist type in code like this:
```cs
public class SomeList<G, T> : SyncList<T> { }
public class SomeListInt : SomeList<string, int> { }
```
This code fixes that problem, and greatly reduces the complexity
of argument lookup.
* linting
Remove all the recursionCount nonsense.
This was added to prevent infinite recursion with types that reference themselves.
No need to check anymore, the weaver can generate readers and writers for types that reference themselves such as:
```cs
class Tree {
Tree child1;
Tree child2;
}
```
This works by the weaver doing it the way the compiler does: Create a function first, memoize it, then write the body. If the body needs the function, it will get itself and issue a call to itself.
Currently, whenever we want to serialize an enum,
we simply serialize the underlying type (byte, short, int)
This works fine, but in order to get the reader and writer
at runtime I need a function for each type.
With this PR, we generate a reader and writer function for enums too,
the function body simply calls the underlying reader and writer.
* throwing Exception instead of returning null
* re-adding null check until later PR
* removing error from test
* removing extra error
* adding comment
* replacing error with throw for abstact
The plan is to remove WeaverLists at some point so moving the functions
out of weaver to here for now and then move them closer to where they
are actaully used when we start to remove WeaverLists.
# Before
This is hard to read:
```
if (ca.AttributeType.FullName == typeof(Mirror.CommandAttribute).FullName) {
...
}
```
# After
```
if (ca.AttributeType.Is<Mirror.CommandAttribute>()) {
...
}
```
# Before
WeaverTypes declared a static variable like this:
```cs
public static TypeReference int32Type;
```
Weavertypes then loaded the variable in SetupTargetTypes like this:
```cs
int32Type = ImportSystemModuleType(currentAssembly, systemModule, "System.Int32");
```
Note we lookup the type with a string, any typo there won't be detected until the code is executed. It will also not be found by the IDE when you click "find references", or when you refactor.
Then we use it like this:
```cs
var intType = WeaverTypes.int32Type;
```
This is a DRY violation: I have to modify 3 different code sections just to say that I want the int32 type.
# After
Get rid of all the duplication, and use the type instead of a string:
```cs
var intType = WeaverTypes.Import<int>();
```
No need for static variable, or to add it in SetupTargetTypes.
* fixing null ref error when local player is destroyed
* removing null objects
* fixing InvalidOperationException
* moving code to its own function
* Update Assets/Mirror/Runtime/ClientScene.cs
* Update ClientScene.cs
Improving logging
- making sure sceneId is always hex
- only logging "Client spawn for ..." if it was successful
* Update ClientSceneTests_OnSpawn.cs
- Adding handlers in Awake instead of Start to make sure they are added before start on headless
- using GetComponent for NetworkManagerListServer
- Adding asserts to make sure values are set
* moving FakeNetworkConnection to common test folder
* adding test for local player destroy
* adding method to clear local player
* temp move test functions
* adding test for destroying non player
* moving asset to setup
* adding tests for destroy message and host mode
* adding ClearLocalPlayer to reset
* Removing manual invoke for Cmd and RPC
There should be no reason to manaully invoke remote code
they are marked with EditorBrowsableState.Never which implies they should not be called by the user
* removing tests
* adding note to guides about removed SyncEvent
* updating Obsolete
making Obsolete error whe used
updating text to say it has been removed
linking to issue
* adding Obsolete note to other references to SyncEvent
* Remove ScriptTemplates to clean up folder
* Update main.yml
Removing script templates from CI
Co-authored-by: James Frowen <jamesfrowendev@gmail.com>
* fix adding error for gernated read writer for abstract class
weaver can not initialize class abstract class so cant not create a reader
this gives a helpful error telling the server to make a custom reader
* adding tests for error message
* fixing typo
* renaming
* fixing expected error messages
Reader code doesn't run on Rpc now if a valid writer can not be found
In future PR write and read functions should be generated together as they share most of the same checks
* replacing assert with haserror
* adding IsSuccess and HasWarning functions
* using IsSuccess
* checking weaverWarnings empty in success
* using HasWarning
* replacing asserts missed by regex
* fixing typo
* adding HasNoErrors function to be used when tests only have warnings
* fixing typo
* making fields public to stop warnings
* simplifying more test files
* adding generated test for other baseclasses
* removing errors when attribute is not in networkbehaviour
* temp weaver tests
* updating weaver tests for monobehaviour
* adding weaver tests for non-networkbehaviour
* moving where serverclient attributes are processed
* removing un-used code
* regenerate tests
* adding check for no connections
Dont need to run Server Update if there are no connections
* adding toggle to disable skip
* formatt
* removing skipUpdateIfNoConnections check, and merging if checks
* removing extra line
* adding tests for NoConnections
* replacing isHeadless with isServerBuild
* renaming startOnHeadless
* fixing isServerBuild bool
* making property a field instead
* replacing isServerBuild for #if UNITY_SERVER
* fixing comment and removing extra lines
* removing system from System.Obsolete
* renaming to autoStartServerBuild
* adding assert to make sure transport is set
this helps people who want to connect without using networkmanager
* moving Transport.activeTransport to setup
* replacing Substitute.For for addComponent
Can't used Substitute for monobehaviours as they will still be null with unity equals
* weaver test for abstract methods
* doing nothing is method is abstract
* not calling base if it is abstract
* adding tests for message to make sure they work
* weaver tests for list read write
* generated tests for list read write
* adding method to check for list type
* temp
* weaver functions for creating read write for list
* generating tests for lists
* adding generated tests for collection writers
tests for read+write for array and array segment
* changing menu path
* adding tests for collections of classes
* swapping order in class name
* tests for Server attribute on virtual methods
test for virtual, abstract and override methods
* adding test for client attribute
* adding error when attribute is put on abstract method
* improving error message
* updating error mesages in tests
* updating to use WeaverTypes
* adding check before error
* class to create test functions
* generated test folder
* generated attribute tests
* adding out function and long type
* generated test file
* using OneTimeSetUp to make tests run faster
* Added Layer Weight to NetworkAnimator
Now NetworkAnimator is aware of each layer weight on it's references
Animator and will sync layer weights across the network.
* NetworkAnimator layers Float equality fix
* Update Assets/Mirror/Components/NetworkAnimator.cs
Co-authored-by: James Frowen <jamesfrowen5@gmail.com>
* Update Assets/Mirror/Components/NetworkAnimator.cs
Co-authored-by: James Frowen <jamesfrowen5@gmail.com>
* Remove GetLayerWeight check every incoming packet as is extern call
Co-authored-by: James Frowen <jamesfrowen5@gmail.com>
* Adding asmdef to telepathy
mirror has to reference telepathy as it is the default transport
this also means that TelepathyTransport has to be in the mirror asmdef
* references telepathy in tests
* formatting asmdef
Note this method is being called in 3 places:
one in MessageClassProcessor and 2 in NetworkBehaviorProcessor.
The NetworkBehaviorProcess is really a don't care, this condition cannot happen since it would not be invoked unless the class extends from NetworkBehavior. In this case, it will always resolve.
but even if it does not resolve, they handle the null case gracefully by not calling the base method.
MessageClassProcessor also calls this method, and if it is null it does not call the base method. That is precisely the behavior we want to resolve#2117
so all 3 places are perfectly fine receiving null.
The only way to trigger the error was #2117
I renamed the method to make it clearer that this may not find the method in the parent class.