Skip to content

Commit

Permalink
Update identifier formats. Merge heroiclabs#123
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Nov 2, 2017
1 parent af8bf7a commit bcca141
Show file tree
Hide file tree
Showing 42 changed files with 1,467 additions and 1,843 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
### Added
- RUDP transport option for client connections.

### Changed
- Consistently Use strings for all ID types.
- Improve runtime hook lookup behaviour.

### [1.1.0] - 2017-10-17
### Added
- Advanced Matchmaking with custom filters and user properties.
Expand Down
63 changes: 63 additions & 0 deletions migrations/20171102123912_format_identifiers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

-- +migrate Up
ALTER TABLE IF EXISTS user_device DROP CONSTRAINT IF EXISTS fk_user_id_ref_users;

UPDATE users SET id = from_uuid(id)::BYTEA;
UPDATE user_device SET user_id = from_uuid(user_id)::BYTEA;

ALTER TABLE IF EXISTS user_device ADD CONSTRAINT fk_user_id_ref_users FOREIGN KEY (user_id) REFERENCES users(id);

UPDATE user_edge SET source_id = from_uuid(source_id)::BYTEA, destination_id = from_uuid(destination_id)::BYTEA;
UPDATE user_edge_metadata SET source_id = from_uuid(source_id)::BYTEA;

UPDATE groups SET id = from_uuid(id)::BYTEA, creator_id = from_uuid(creator_id)::BYTEA;
UPDATE group_edge SET source_id = from_uuid(source_id)::BYTEA, destination_id = from_uuid(destination_id)::BYTEA;

UPDATE message SET user_id = from_uuid(user_id)::BYTEA, message_id = from_uuid(message_id)::BYTEA;

UPDATE storage SET id = from_uuid(id)::BYTEA, user_id = from_uuid(user_id)::BYTEA;

UPDATE leaderboard_record SET id = from_uuid(id)::BYTEA, owner_id = from_uuid(owner_id)::BYTEA;

UPDATE purchase SET user_id = from_uuid(user_id)::BYTEA;

UPDATE notification SET id = from_uuid(id)::BYTEA, user_id = from_uuid(user_id)::BYTEA, sender_id = from_uuid(sender_id)::BYTEA;

-- +migrate Down
ALTER TABLE IF EXISTS user_device DROP CONSTRAINT IF EXISTS fk_user_id_ref_users;

UPDATE users SET id = to_uuid(id)::BYTEA;
UPDATE user_device SET user_id = to_uuid(user_id)::BYTEA;

ALTER TABLE IF EXISTS user_device ADD CONSTRAINT fk_user_id_ref_users FOREIGN KEY (user_id) REFERENCES users(id);

UPDATE user_edge SET source_id = to_uuid(source_id)::BYTEA, destination_id = to_uuid(destination_id)::BYTEA;
UPDATE user_edge_metadata SET source_id = to_uuid(source_id)::BYTEA;

UPDATE groups SET id = to_uuid(id)::BYTEA, creator_id = to_uuid(creator_id)::BYTEA;
UPDATE group_edge SET source_id = to_uuid(source_id)::BYTEA, destination_id = to_uuid(destination_id)::BYTEA;

UPDATE message SET user_id = to_uuid(user_id)::BYTEA, message_id = to_uuid(message_id)::BYTEA;

UPDATE storage SET id = to_uuid(id)::BYTEA, user_id = to_uuid(user_id)::BYTEA;

UPDATE leaderboard_record SET id = to_uuid(id)::BYTEA, owner_id = to_uuid(owner_id)::BYTEA;

UPDATE purchase SET user_id = to_uuid(user_id)::BYTEA;

UPDATE notification SET id = to_uuid(id)::BYTEA, user_id = to_uuid(user_id)::BYTEA, sender_id = to_uuid(sender_id)::BYTEA;
22 changes: 11 additions & 11 deletions pkg/multicode/client_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ const (
)

var ErrClientInstanceClosed = errors.New("client instance closed")
var ErrClientInstanceUnreliableDataTooLarge = errors.New("client instance unreliable data too large")
var ErrClientInstanceNotConnected = errors.New("client instance not connected")
var ErrClientInstanceSendBufferFull = errors.New("client instance reliable send buffer full")

//var ErrClientInstancePacketDataTooLarge = errors.New("client instance packet data too large")

type ClientInstance struct {
sync.Mutex
logger *zap.Logger
Expand Down Expand Up @@ -131,7 +130,7 @@ func NewClientInstance(logger *zap.Logger, addr *net.UDPAddr, serverConn *Netcod
incomingPacketCh: make(chan netcode.Packet, netcode.PACKET_QUEUE_SIZE),
outgoingPacketData: make([]byte, netcode.MAX_PACKET_BYTES),

unreliableController: NewReliablePacketController(maxPacketSize, maxPacketFragments),
unreliableController: NewReliablePacketController(1024, 1),
unreliableReceiveBuffer: NewSequenceBufferReceived(256),

reliableCh: make(chan []byte, netcode.PACKET_QUEUE_SIZE),
Expand Down Expand Up @@ -244,6 +243,7 @@ func (c *ClientInstance) IsConnected() bool {
// An external routine is expected to continuously call this, otherwise
// no input attributed to this client instance will be processed.
func (c *ClientInstance) Read() ([]byte, bool, error) {
readLoop:
for {
select {
case reliableData := <-c.reliableCh:
Expand Down Expand Up @@ -342,17 +342,17 @@ func (c *ClientInstance) Read() ([]byte, bool, error) {
if err != nil {
c.Unlock()
c.logger.Debug("error processing reliable packet message ID", zap.Error(err))
continue
continue readLoop
}
messageLengthUint16, err := ReadVariableLengthUint16(rw)
if err != nil {
c.Unlock()
c.logger.Debug("error processing reliable packet message length", zap.Error(err))
continue
continue readLoop
}
if messageLengthUint16 == 0 {
c.Unlock()
continue
continue readLoop
}

messageLength := int(messageLengthUint16)
Expand All @@ -363,7 +363,7 @@ func (c *ClientInstance) Read() ([]byte, bool, error) {
if err != nil {
c.Unlock()
c.logger.Debug("error processing reliable packet read buffer", zap.Error(err))
continue
continue readLoop
}
} else {
rw.SeekRead(rw.readPosition + messageLength)
Expand Down Expand Up @@ -424,10 +424,10 @@ func (c *ClientInstance) Read() ([]byte, bool, error) {

// NOTE: Only for payload data packets, other protocol-level messages MUST be sent through other functions.
func (c *ClientInstance) Send(payloadData []byte, reliable bool) error {
//if len(payloadData) > netcode.MAX_PACKET_BYTES {
// c.logger.Warn("server attempting to send packet data exceeding max length, dropping packet")
// return ErrClientInstancePacketDataTooLarge
//}
if !reliable && len(payloadData) > FRAGMENT_SIZE {
c.logger.Warn("server attempting to send unreliable packet data exceeding unreliable max length, dropping packet")
return ErrClientInstanceUnreliableDataTooLarge
}

c.Lock()
if c.stopped || !c.connected {
Expand Down
Loading

0 comments on commit bcca141

Please sign in to comment.